python解方程

来源:互联网 发布:淘宝上买的轮毂可靠吗 编辑:程序博客网 时间:2024/06/04 23:23


# -*- coding:utf-8 -*-import numpy as np# 使用np.linalg.solve()解一元线性方程组,待解方程为:##  x + 2y +  z = 7# 2x -  y + 3z = 7# 3x +  y + 2z =1# 系数矩阵A = np.array([[1, 2, 1], [2, -1, 3], [3, 1, 2]])B = np.array([7, 7, 18])np.array([ 7,  7, 18])x = np.linalg.solve(A, B)print(x)np.array([ 7.,  1., -2.])print( np.dot(A, x))#检验正确性,结果为B

其他功能,比如求矩阵的秩,参考:

http://www.cnblogs.com/moon1992/p/4960700.html