Untitled6.ipynb - Colab
Untitled6.ipynb - Colab
ipynb - Colab
#1.linearsolve
import numpy as np
import scipy.linalg as la
A=np.array([[1,1,2],[-1,-2,3],[3,-7,6]])
print("A:\n",A)
B=np.array([7,5,1])
print("B:\n",B)
x=la.solve(A,B)
print("x:\n",x)
A:
[[ 1 1 2]
[-1 -2 3]
[ 3 -7 6]]
B:
[7 5 1]
x:
[-0.6 2. 2.8]
#2 a)
D=np.array([[10,2,3],[12,-7,15],[-15,10,-11]])
a=(D.T)
print("transpose of D:\n",a)
transpose of D:
[[ 10 12 -15]
[ 2 -7 10]
[ 3 15 -11]]
#b)
b=np.linalg.det(D)
print(b)
-871.0000000000001
#c
c=np.linalg.inv(D)
print("inverse is :\n",c)
inverse is :
[[ 0.08381171 -0.05970149 -0.05855339]
[ 0.10677382 0.07462687 0.13088404]
[-0.01722158 0.14925373 0.10792193]]
#3 a)
#b
print("\n Rank",D.rank())
Rank 3
#c
print("\n nullspace",D.nullspace())
nullspace []
#d
print("columnspace is",D.columnspace())
columnspace is [Matrix([
[6],
[2],
[4]]), Matrix([
[18],
https://colab.research.google.com/drive/1Sp6NRSjUgGzGY6szmtDpCjqos7ZoYHBY#scrollTo=h2_mlj02Cfn0&printMode=true 2/3
9/23/24, 3:24 PM Untitled6.ipynb - Colab
[12],
[15]]), Matrix([
[3],
[1],
[3]])]
#4
import scipy.linalg as la
A=np.array([[2,1],[1,2]])
print("A:\n",A)
B=np.array([5,7])
print("B:\n",B)
x=la.solve(A,B)
print("x:\n",x)
A:
[[2 1]
[1 2]]
B:
[5 7]
x:
[1. 3.]
#5
A=np.array([[1,2,3],[4,5,6],[7,8,10]])
print("A\n",A)
B=np.array([3,6,9])
print("B\n",B)
x=la.solve(A,B)
print(x)
A
[[ 1 2 3]
[ 4 5 6]
[ 7 8 10]]
B
[3 6 9]
[-1.00000000e+00 2.00000000e+00 -2.22044605e-16]
https://colab.research.google.com/drive/1Sp6NRSjUgGzGY6szmtDpCjqos7ZoYHBY#scrollTo=h2_mlj02Cfn0&printMode=true 3/3