(雖然我知道matlab解矩陣更快!!!!)
Code:
import numpy as lp
A = []
# 讀入矩陣A,每一元素 a_ij=1/(i+j),在此裡階數為10*10
for i in range(1, 11):
tmp = []
for j in range(1,11):
tmp.append(1/(i+j))
A.append(tmp)
b = []
#讀入矩陣b,每一元素 b_ij=1/i,在此裡為10*1
for i in range(1, 11):
b.append(1/i)
#取A的反矩陣
A_inverse=lp.linalg.inv(A)
# 矩陣相乘,X=b/A
print(lp.dot(A_inverse,b))
所得到的10個解為:
1.10013331e+02 -2.97063181e+03 3.43298487e+04 -2.10283001e+05 7.57056679e+05 -1.68241924e+06
2.33487030e+06 -1.97010848e+06 9.24273720e+05
-1.84859206e+05
沒有留言:
張貼留言