(1)估计5到20阶Hilbert矩阵的范数条件数(2)设nnRA111111111011001,先随机地选取nRx,并计算出xAbn;然后再用列主元Gauss消去法求解该方程组,假定计算解为x。试对n从5到30估计计算解x的精度,并且与真实相对误差作比较。解(1)分析:利用for使n从5循环到20,利用()hilb函数得到Hilbert矩阵A;先将算法2.5.1编制成通用的子程序,利用算法2.5.1编成的子程序)(Boptv,对TAB求解,得到1A的一个估计值vv~;再利用inf),(Anorm得到A;则条件数inf),(1AnormvAAK。另,矩阵A的范数条件数可由inf),(Acond直接算出,两者可进行比较。程序为1算法2.5.1编成的子程序)(Boptvfunctionv=opt(B)k=1;n=length(B);x=1./n*ones(n,1);whilek==1w=B*x;v=sign(w);z=B'*v;ifnorm(z,inf)=z'*xv=norm(w,1);k=0;elsex=zeros(n,1);[s,t]=max(abs(z));x(t)=1;k=1;endendend2问题(1)求解ex2_1forn=5:20A=hilb(n);B=inv(A.');v=opt(B);K1=v*norm(A,inf);K2=cond(A,inf);disp(['n=',num2str(n)])disp(['估计条件数为',num2str(K1)])disp(['实际条件数为',num2str(K2)])end计算结果为n=5估计条件数为943656实际条件数为943656n=6估计条件数为29070279.0028实际条件数为29070279.0028n=7估计条件数为985194887.5079实际条件数为985194887.5079n=8估计条件数为33872789099.7717实际条件数为33872789099.7717n=9估计条件数为1099649467886.422实际条件数为1099649467886.422n=10估计条件数为35353368771750.67实际条件数为35353368771750.67n=11估计条件数为1232433965549344实际条件数为1232433965549344Warning:Matrixisclosetosingularorbadlyscaled.Resultsmaybeinaccurate.RCOND=2.547634e-17.Inex2_1at3Warning:Matrixisclosetosingularorbadlyscaled.Resultsmaybeinaccurate.RCOND=2.547634e-17.Incondat47Inex2_1at6n=12估计条件数为3.924509699943713e+16实际条件数为3.924509699943713e+16Warning:Matrixisclosetosingularorbadlyscaled.Resultsmaybeinaccurate.RCOND=7.847381e-19.Inex2_1at3Warning:Matrixisclosetosingularorbadlyscaled.Resultsmaybeinaccurate.RCOND=7.847381e-19.Incondat47Inex2_1at6n=13估计条件数为1.271531365675327e+18实际条件数为1.271531365675327e+18Warning:Matrixisclosetosingularorbadlyscaled.Resultsmaybeinaccurate.RCOND=2.246123e-18.Inex2_1at3Warning:Matrixisclosetosingularorbadlyscaled.Resultsmaybeinaccurate.RCOND=2.246123e-18.Incondat47Inex2_1at6n=14估计条件数为4.138368891288374e+17实际条件数为4.138368891288374e+17Warning:Matrixisclosetosingularorbadlyscaled.Resultsmaybeinaccurate.RCOND=8.491876e-19.Inex2_1at3Warning:Matrixisclosetosingularorbadlyscaled.Resultsmaybeinaccurate.RCOND=8.491876e-19.Incondat47Inex2_1at6n=15估计条件数为4.633108811649674e+17实际条件数为5.234289848563619e+17Warning:Matrixisclosetosingularorbadlyscaled.Resultsmaybeinaccurate.RCOND=9.137489e-19.Inex2_1at3Warning:Matrixisclosetosingularorbadlyscaled.Resultsmaybeinaccurate.RCOND=9.137489e-19.Incondat47Inex2_1at6n=16估计条件数为8.036171638973166e+17实际条件数为8.036171638973167e+17Warning:Matrixisclosetosingularorbadlyscaled.Resultsmaybeinaccurate.RCOND=6.244518e-19.Inex2_1at3Warning:Matrixisclosetosingularorbadlyscaled.Resultsmaybeinaccurate.RCOND=6.244518e-19.Incondat47Inex2_1at6n=17估计条件数为1.40155292233093e+18实际条件数为1.40155292233093e+18Warning:Matrixisclosetosingularorbadlyscaled.Resultsmaybeinaccurate.RCOND=4.693737e-19.Inex2_1at3Warning:Matrixisclosetosingularorbadlyscaled.Resultsmaybeinaccurate.RCOND=4.693737e-19.Incondat47Inex2_1at6n=18估计条件数为2.550260641580651e+18实际条件数为2.800000737997893e+18Warning:Matrixisclosetosingularorbadlyscaled.Resultsmaybeinaccurate.RCOND=4.264685e-19.Inex2_1at3Warning:Matrixisclosetosingularorbadlyscaled.Resultsmaybeinaccurate.RCOND=4.264685e-19.Incondat47Inex2_1at6n=19估计条件数为2.411858563109357e+18实际条件数为2.411858563109357e+18Warning:Matrixisclosetosingularorbadlyscaled.Resultsmaybeinaccurate.RCOND=1.351364e-19.Inex2_1at3Warning:Matrixisclosetosingularorbadlyscaled.Resultsmaybeinaccurate.RCOND=1.351364e-19.Incondat47Inex2_1at6n=20估计条件数为2.31633670586674e+18实际条件数为6.37335273308473e+18结果分析随着矩阵阶数增加,估计值误差开始出现,20,17,16,15n时估计条件数与实际值存在误差;且条件数很大,Hilbert矩阵为病态的。解(2)分析:先根据题目要求,利用for和()rand使n从5循环到30,作出A和随机的x,并计算出Axb;然后再利用第一章习题中得到的)(],,[AGaussColPUL和),,,,(PULbAGaussx用列主元Gauss消去法求解该方程组,假定计算解为1x,得1*xAbr,利用第(1)问所得函数)).'((Ainvopt计算1A的一个估计值,利用inf),(norm计算Abr,,的无穷范数,则1x的相对误差估计为))/norm(b,(A,A.'))*norm)*opt(inv(norm(r,pinfinfinf1,真实相对误差为))/norm(x,,norm(x-xpinfinf12。程序为1列主元Gauss消去法求解该方程组的程序为A的LU分解:function[L,U,P]=GaussCol(A)n=length(A);fork=1:n-1[s,t]=max(abs(A(k:n,k)));p=t+k-1;temp=A(k,1:n);A(k,1:n)=A(p,1:n);A(p,1:n)=temp;u(k)=p;ifA(k,k)~=0A(k+1:n,k)=A(k+1:n,k)/A(k,k);A(k+1:n,k+1:n)=A(k+1:n,k+1:n)-A(k+1:n,k)*A(k,k+1:n);elsebreak;endendL=tril(A);U=triu(A);L=L-diag(diag(L))+diag(ones(1,n));P=eye(n);fori=1:n-1temp=P(i,:);P(i,:)=P(u(i),:);P(u(i),:)=temp;endend高斯消去法解线性方程组functionx=Gauss(A,b,L,U,P)ifnargin5P=eye(length(A));endn=length(A);b=P*b;forj=1:n-1b(j)=b(j)/L(j,j);b(j+1:n)=b(j+1:n)-b(j)*L(j+1:n,j);endb(n)=b(n)/L(n,n);y=b;forj=n:-1:2y(j)=y(j)/U(j,j);y(1:j-1)=y(1:j-1)-y(j)*U(1:j-1,j);endy(1)=y(1)/U(1,1);x=y;end2问题(2)求解ex2_2forn=5:30A=2*eye(n)+tril(-1*ones(n));A(1:n-1,n)=ones(n-1,1);x=100*rand(n,1);b=A*x;[L,U,P]=GaussCol(A);x1=Gauss(A,b,L,U,P);r=b-A*x1;p1=norm(r,inf)*opt(inv(A.'))*norm(A,inf)/norm(b,inf);p2=norm(x-x1,inf)/norm(x,inf);disp(['n=',num2str(n)])disp(['估计相对误差为',num2str(p1)])disp(['实际相对误差为',num2str(p2)])y1(n-4)=p1;y2(n-4)=p2;endplot(5:30,y1,5:30,y2)legend('估计相对误差','实际相对误差')计算结果为n=5估计相对误差为2.8265e-15实际相对误差为3.1615e-16n=6估计相对误差为3.3434e-15实际相对误差为2.8523e-16n=7估计相对误差为9.882e-16实际相对误差为1.7941e-16n=8估计相对误差为4.8733e-14实际相对误差为1.0891e-14n=9估计相对误差为2.2282e-14