由下列方程组,求解x,y,z。
2x-y+2.5z=2.3
x+3.4y-z=4.2
-x+2.9y+1.8z=3.1
import numpy as np
A = np.array([[2,-1,2.5], [1,3.4,-1], [-1,2.9,1.8]])
B = np.array([2.3,4.2,3.1])
X = np.linalg.inv(A).dot(B)
x,y,z=X
print("x=",x)
print("y=",y)
print("z=",z)
结果为:
x= 1.0264816420930907
y= 1.0907776814108123
z= 0.5351257588898526