1 矩阵的相关运算(和差、数乘、对应乘、逆)
1.1 产生需要利用的矩阵
import numpy as np
from IPython.core.interactiveshell import InteractiveShell
InteractiveShell.ast_node_interactivity = "all"
a=np.array([[1,2,3],[4,5,6]]);a
b=np.array([[1,2],[3,4],[5,6]]);b
c=np.array([[1,2,3]]);c
d=np.array([[9,8,7],[3,2,1]]);d
1.2 矩阵的加减法(即对应元素相加减、同型)
sum=a+d;sum
fangsuo=3*a;fangsuo
chengfa=np.dot(a,b);chengfa
dy=a*d;dy
zz=b.T;zz
1.3 方阵的逆、行列式、秩
e=np.array([[1,2],[3,4]]);e
inv_e=np.linalg.inv(e);inv_e
det_e=np.linalg.det(e);det_e
rank_e=np.linalg.matrix_rank(e);rank_e
2 解线性方程组:AX=b
2.1 普通解法
A=np.array([[10,-1,-2],[-1,10,-2],[-1,-1,5]]);A
b=np.array([72,83,42]);b
X=np.dot(np.linalg.inv(A),b);X
X_=np.linalg.solve(A,b);X_
2.2 符号解法
from sympy import symbols,Eq,solve
x,y,z=sympy.symbols('x y z')
eqs=[sympy.Eq(10*x-y-2*z,72),
sympy.Eq(-x+10*y-2*z,83),
sympy.Eq(-x-y+5*z,42)]
print(sympy.solve(eqs,[x,y,z]))