用Python解决5个线性方程组

JSh*_*hoe 0 python equation-solving

我尝试过使用矩阵,但它失败了.我看过外部模块和外部程序,但没有一个有效.如果有人可以分享一些有用的提示或代码,谢谢.

tsk*_*zzy 5

当你说矩阵方法不起作用时,我不确定你的意思.这是解决这些类型问题的标准方法.

从线性代数的角度来看,求解5个线性方程是微不足道的.它可以使用任何数量的方法来解决.您可以使用高斯消元法,找到逆,Cramer规则等.

如果你很懒,你总是可以求助于图书馆.Sympy和Numpy都可以轻松解决线性方程.


Hug*_*ell 5

import numpy
import scipy.linalg

m = numpy.matrix([
    [1, 1, 1, 1, 1],
    [16, 8, 4, 2, 1],
    [81, 27, 9, 3, 1],
    [256, 64, 16, 4, 1],
    [625, 125, 25, 5, 1]
])

res = numpy.matrix([[1],[2],[3],[4],[8]])

print scipy.linalg.solve(m, res)
Run Code Online (Sandbox Code Playgroud)

回报

[[ 0.125]
 [-1.25 ]
 [ 4.375]
 [-5.25 ]
 [ 3.   ]]
Run Code Online (Sandbox Code Playgroud)

(a,b,c,d,e的解决方案系数)