MATLAB 作业二参考答案1、试求下面线性代数方程的解析解与数值解,并检验解的正确性。
2932114010110503848246303356684953X -----⎡⎤⎡⎤⎢⎥⎢⎥----⎢⎥⎢⎥=⎢⎥⎢⎥---⎢⎥⎢⎥------⎣⎦⎣⎦【求解】求出A , [A;B ] 两个矩阵的秩,可见二者相同,所以方程不是矛盾方程,应该有无穷多解。
>> A=[2,-9,3,-2,-1; 10,-1,10,5,0; 8,-2,-4,-6,3; -5,-6,-6,-8,-4]; B=[-1,-4,0; -3,-8,-4; 0,3,3; 9,-5,3]; [rank(A), rank([A B])] ans =4 4用下面的语句可以求出方程的解析解,并可以验证该解没有误差。
>> x0=null(sym(A));x_analytical=sym(A)\B; syms a; x=a*[x0 x0 x0]+x_analytical x =[ a+967/1535, a-943/1535, a-159/1535] [ -1535/1524*a, -1535/1524*a, -1535/1524*a][ -3659/1524*a-1807/1535,-3659/1524*a-257/1535,-3659/1524*a-141/1535] [ 1321/508*a+759/1535, 1321/508*a-56/1535, 1321/508*a-628/1535] [ -170/127*a-694/307, -170/127*a+719/307, -170/127*a+103/307] >> A*x-B ans =[ 0, 0, 0][ 0, 0, 0][ 0, 0, 0][ 0, 0, 0]用数值解方法也可以求出方程的解,但会存在误差,且与任意常数a 的值有关。
>> x0=null(A); x_numerical=A\B; syms a;x=a*[x0 x0 x0]+x_numerical; vpa(x,10)ans =[ .2474402553*a+.1396556436, .2474402553*a-.6840666849, .2474402553*a-.1418 420333][-.2492262414*a+.4938507789,-.2492262414*a+.7023776988e-1,-.2492262414*a+ .3853511888e-1][ -.5940839201*a, -.5940839201*a, -.5940839201*a][ .6434420813*a-.7805411315, .6434420813*a-.2178190763,.6434420813*a-.50860 89095][-.3312192394*a-1.604263460, -.3312192394*a+2.435364854,-.3312192394*a+.3867176824]>> A*x-Bans =[ 1/18014398509481984*a, 1/18014398509481984*a, 1/18014398509481984*a] [ -5/4503599627370496*a, -5/4503599627370496*a, -5/4503599627370496*a] [ -25/18014398509481984*a, -25/18014398509481984*a,-25/18014398509481984*a][ 13/18014398509481984*a, 13/18014398509481984*a, 13/18014398509481984*a]2、求解下面的联立方程,并检验得出的高精度数值解(准解析解)的精度。