给一个非齐次线性方程组:
3 * x1 + 4 * x2 + 5 * x3 =542 * x1 + 5 * x2 + 4 * x3 =444 * x1 + 6 * x2 + 3 * x3 =55
求解结果为
x1=7x2=2x3=5
现在利用python求解函数的模块直接求答案。
# 求解线性方程组from scipy import linalgimport numpy as npX_temp = [[3, 4, 5],[2, 5, 4],[4, 6, 3]]X_temp=np.array(X_temp)#一定要转换为矩阵形式#X_temp代表系数矩阵C=[54,44,55]#C为常数列C = np.array(C) # b代表常数列X = linalg.solve(X_temp,C)print(X)
运行结果