Professional Documents
Culture Documents
CLASS 8 AUG 22 SEM 3 - Jupyter Notebook
CLASS 8 AUG 22 SEM 3 - Jupyter Notebook
CLASS 8
𝑥 1 + 2𝑥 2 − 𝑥 3 = 1
2𝑥 1 + 𝑥 2 + 4𝑥 3 = 2
3𝑥 1 + 3𝑥 2 + 4𝑥 3 = 1
In [1]:
import numpy as np
In [2]:
A=np.array([[1,2,-1],[2,1,4],[3,3,4]])
B=np.array([1,2,1])
np.linalg.solve(A,B)
Out[2]:
In [6]:
A=np.matrix([[1,2,-1],[2,1,4],[3,3,4]])
B=np.matrix([1,2,1])
np.linalg.solve(A,B)
--------------------------------------------------------------------------
-
ValueError Traceback (most recent call las
t)
Input In [6], in <cell line: 3>()
1 A=np.matrix([[1,2,-1],[2,1,4],[3,3,4]])
2 B=np.matrix([1,2,1])
----> 3 np.linalg.solve(A,B)
In [5]:
A=np.matrix([[1,2,-1],[2,1,4],[3,3,4]])
B=np.matrix([[1],[2],[1]])
np.linalg.solve(A,B)
Out[5]:
matrix([[ 7.],
[-4.],
[-2.]])
In [8]:
A=np.matrix([[1,-1,1,-1],[1,-1,1,1],[4,-4,4,0],[-2,2,-2,1]])
B=np.matrix([[2],[0],[4],[-3]])
np.linalg.solve(A,B)
--------------------------------------------------------------------------
-
LinAlgError Traceback (most recent call las
t)
Input In [8], in <cell line: 3>()
1 A=np.matrix([[1,-1,1,-1],[1,-1,1,1],[4,-4,4,0],[-2,2,-2,1]])
2 B=np.matrix([[2],[0],[4],[-3]])
----> 3 np.linalg.solve(A,B)
2𝑥 1 + 3𝑥 2 + 𝑥 3 = 0
𝑥 1 − 𝑥 2 − 3𝑥 3 = 0
In [10]:
A=np.matrix([[2,3,1],[1,-1,-2]])
B=np.matrix([[0],[0]])
np.linalg.solve(A,B)
--------------------------------------------------------------------------
-
LinAlgError Traceback (most recent call las
t)
Input In [10], in <cell line: 3>()
1 A=np.matrix([[2,3,1],[1,-1,-2]])
2 B=np.matrix([[0],[0]])
----> 3 np.linalg.solve(A,B)
1)
𝑥1 + 2𝑥2 − 𝑥3 = −1
2𝑥1 + 𝑥2 + 4𝑥3 = 2
3𝑥1 + 3𝑥2 + 4𝑥3 = 1
In [12]:
A=np.matrix([[1,2,-1],[2,1,4],[3,3,4]])
B=np.matrix([[-1],[2],[1]])
np.linalg.solve(A,B)
Out[12]:
matrix([[ 1.66666667e+00],
[-1.33333333e+00],
[-3.70074342e-16]])
2)
𝑥1 − 𝑥2 + 𝑥3 − 𝑥4 = 2
𝑥1 − 𝑥2 + 𝑥3 + 𝑥4 = 0
4𝑥1 − 4𝑥2 + 4𝑥3 = 4
−2𝑥1 + 2𝑥2 − 2𝑥3 + 𝑥4 = −3
In [13]:
A=np.matrix([[1,-1,1,-1],[1,-1,1,1],[4,-4,4],[-2,2,-2,1]])
B=np.matrix([[2],[0],[4],[-3]])
np.linalg.solve(A,B)
C:\Users\HP\Pranav\lib\site-packages\numpy\matrixlib\defmatrix.py:145: Vis
ibleDeprecationWarning: Creating an ndarray from ragged nested sequences
(which is a list-or-tuple of lists-or-tuples-or ndarrays with different le
ngths or shapes) is deprecated. If you meant to do this, you must specify
'dtype=object' when creating the ndarray.
arr = N.array(data, dtype=dtype, copy=copy)
--------------------------------------------------------------------------
-
LinAlgError Traceback (most recent call las
t)
Input In [13], in <cell line: 3>()
1 A=np.matrix([[1,-1,1,-1],[1,-1,1,1],[4,-4,4],[-2,2,-2,1]])
2 B=np.matrix([[2],[0],[4],[-3]])
----> 3 np.linalg.solve(A,B)
3)
𝑥1 + 2𝑥2 − 𝑥3 = 1
2𝑥1 + 𝑥2 + 5𝑥3 = 2
3𝑥1 + 3𝑥2 + 4𝑥3 = 1
In [14]:
A=np.matrix([[1,2,-1],[2,1,5],[3,3,4]])
B=np.matrix([[1],[2],[1]])
np.linalg.solve(A,B)
Out[14]:
matrix([[-1.04293886e+16],
[ 6.63688366e+15],
[ 2.84437871e+15]])
4)
𝑥1 + 2𝑥2 + 𝑥3 = 4
4𝑥1 + 5𝑥2 + 6𝑥3 = 7
7𝑥1 + 8𝑥2 + 9𝑥3 = 10
In [15]:
A=np.matrix([[1,2,1],[4,5,6],[7,8,9]])
B=np.matrix([[4],[7],[10]])
np.linalg.solve(A,B)
Out[15]:
matrix([[-2.00000000e+00],
[ 3.00000000e+00],
[-3.48927236e-16]])
In [ ]: