另一種方法,scipy尋根函數求方程組的解: 點擊跳轉.
用scipy.linalg.slove求解
問題:求解下列線性方程組
程序,如下
import numpy as np
a = np.array([[3, 2, 0], [1, -1, 0], [0, 5, 1]])
# 係數矩陣
b = np.array([2, 4, -1])
from scipy import linalg
x = linalg.solve(a, b)
print(x)
結果
[ 2. -2. 9.]
# 依次爲x, y, z