目录
2-2-1
import math
import numpy
from numpy import *
import numpy as np
B1=matrix( [[-1, 1, 0, 0, 0 ], [-1, 0, 0, 1, 0 ], [ -1, 0, 0, 0, 1 ],[ 0,-1,1,0,0] ,
[0,-1,0,1,0 ],[0,-1,0,0,0],[0,0,-1,1,0],[0,0,-1,0,1],[0,0,0,0,-1]])
#第一问的系数矩阵
B2=matrix([[ -1, 1, 0, 0, 0,0 ], [-1, 0, 0, 1, 0,0 ], [ -1, 0, 0, 0, 1,0 ],[0,-1,1,0,0,0] ,
[0,-1,0,1,0 ,0],[ 0,-1,0,0,0,1],[0,0,-1,1,0,0],[0,0,-1,0,1,0],[0,0,0,0,-1,1]])
#后两问的系数矩阵
l=matrix ([[-1], [4], [5], [8], [16], [ 2 ], [-13 ], [-20 ], [-1 ] ])
#常数向量
P =matrix( [ [10.0/204.1, 0, 0, 0, 0, 0, 0, 0, 0 ],
[0, 10.0/188.7, 0, 0, 0, 0, 0, 0, 0 ],
[0, 0, 10.0/344.8 ,0, 0, 0, 0, 0, 0 ],
[0, 0, 0, 10.0/149.2, 0, 0, 0, 0, 0 ],
[0, 0, 0, 0, 10.0/142.9, 0, 0, 0, 0 ],
[0, 0, 0, 0, 0, 10.0/250.0, 0, 0, 0 ],
[0, 0, 0, 0, 0, 0, 10.0/128.2, 0, 0 ],
[0, 0, 0, 0, 0, 0, 0, 10.0/98.0, 0 ],
[0, 0, 0, 0, 0, 0, 0, 0, 10.0/196.1 ] ])
S=matrix ([[1], [1], [1], [1], [1], [1]])
#计算
N=B1.T*P*B1
xc=N.I*B1.T*P*l
Vxc=B1*xc-l
Qxc=N.I
print("改正数Vxc=")#输出改正数和协因数阵(1)
set_printoptions(precision=4)
print(Vxc)
print("协因数阵Qxc=")
set_printoptions(precision=4)
print(Qxc)
#########################################################
#第二问
W=B2.T* P *l
xr=(B2.T*P*B2+S*S.T).I*W
Vxr=B2*xr-l
Qxr=(B2.T*P*B2+S*S.T).I-((B2.T*P*B2+S*S.T).I*S*S.T)*(B2.T*P*B2+S*S.T).I
print("改正数Vxr=")#输出改正数和协因数阵(2)
set_printoptions(precision=4)
print(Vxr)
print("协因数阵Qxr=")
set_printoptions(precision=4)
print(Qxr)
#第三问################################################################
Ns=B2.T*P*B2
Px=matrix( [ [1, 0, 0, 0, 0, 0],
[0, 1, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 1, 0],
[0, 0, 0, 0, 0, 1]])
Ss=Px*S
xs=(B2.T*P*B2+Ss*Ss.T).I*W
Vxs=B2*xs-l
Qxs=(B2.T*P*B2+Ss*Ss.T).I*Ns*(B2.T*P*B2+Ss*Ss.T).I
pr