1、(1 ) 估计 5 到 20 阶 Hilbert 矩阵的 范数条件数(2 ) 设 ,先随机地选取 ,并计算出 ;nRA11011 nRxxAbn然后再用列主元 Gauss 消去法求解该方程组,假定计算解为 。试对 n 从 5 到 30 估计计算x解 的精度,并且与真实相对误差作比较。x解(1)分析:利用 使 从 5 循环到 20,利用 函数得到 Hilbert 矩阵 ;先将算forn()hilbA法 2.5.1 编制成通用的子程序,利用算法 2.5.1 编成的子程序 ,对 求解,)(BoptvT得到 的一个估计值 ;再利用 得到 ;则条件数1Avinf),(Aorm。inf),(AorK另,矩
2、阵 的 范数条件数可由 直接算出,两者可进行比较。if),(cd程序为 1 算法 2.5.1 编成的子程序 )(Boptvfunction v=opt(B)k=1;n=length(B);x=1./n*ones(n,1);while k=1w=B*x;v=sign(w);z=B*v;if norm(z,inf) In ex2_1 at 3 Warning: Matrix is close to singular or badly scaled. Results may beinaccurate. RCOND = 2.547634e-17. In cond at 47In ex2_1 at 6
3、n=12估计条件数为 3.924509699943713e+16实际条件数为 3.924509699943713e+16Warning: Matrix is close to singular or badly scaled. Results may beinaccurate. RCOND = 7.847381e-19. In ex2_1 at 3 Warning: Matrix is close to singular or badly scaled. Results may beinaccurate. RCOND = 7.847381e-19. In cond at 47In ex2_1
4、at 6 n=13估计条件数为 1.271531365675327e+18实际条件数为 1.271531365675327e+18Warning: Matrix is close to singular or badly scaled. Results may beinaccurate. RCOND = 2.246123e-18. In ex2_1 at 3 Warning: Matrix is close to singular or badly scaled. Results may beinaccurate. RCOND = 2.246123e-18. In cond at 47In e
5、x2_1 at 6 n=14估计条件数为 4.138368891288374e+17实际条件数为 4.138368891288374e+17Warning: Matrix is close to singular or badly scaled. Results may beinaccurate. RCOND = 8.491876e-19. In ex2_1 at 3 Warning: Matrix is close to singular or badly scaled. Results may beinaccurate. RCOND = 8.491876e-19. In cond at 4
6、7In ex2_1 at 6 n=15估计条件数为 4.633108811649674e+17实际条件数为 5.234289848563619e+17Warning: Matrix is close to singular or badly scaled. Results may beinaccurate. RCOND = 9.137489e-19. In ex2_1 at 3 Warning: Matrix is close to singular or badly scaled. Results may beinaccurate. RCOND = 9.137489e-19. In cond
7、 at 47In ex2_1 at 6 n=16估计条件数为 8.036171638973166e+17实际条件数为 8.036171638973167e+17Warning: Matrix is close to singular or badly scaled. Results may beinaccurate. RCOND = 6.244518e-19. In ex2_1 at 3 Warning: Matrix is close to singular or badly scaled. Results may beinaccurate. RCOND = 6.244518e-19. In
8、 cond at 47In ex2_1 at 6 n=17估计条件数为 1.40155292233093e+18实际条件数为 1.40155292233093e+18Warning: Matrix is close to singular or badly scaled. Results may beinaccurate. RCOND = 4.693737e-19. In ex2_1 at 3 Warning: Matrix is close to singular or badly scaled. Results may beinaccurate. RCOND = 4.693737e-19.
9、 In cond at 47In ex2_1 at 6 n=18估计条件数为 2.550260641580651e+18实际条件数为 2.800000737997893e+18Warning: Matrix is close to singular or badly scaled. Results may beinaccurate. RCOND = 4.264685e-19. In ex2_1 at 3 Warning: Matrix is close to singular or badly scaled. Results may beinaccurate. RCOND = 4.264685
10、e-19. In cond at 47In ex2_1 at 6 n=19估计条件数为 2.411858563109357e+18实际条件数为 2.411858563109357e+18Warning: Matrix is close to singular or badly scaled. Results may beinaccurate. RCOND = 1.351364e-19. In ex2_1 at 3 Warning: Matrix is close to singular or badly scaled. Results may beinaccurate. RCOND = 1.3
11、51364e-19. In cond at 47In ex2_1 at 6 n=20估计条件数为 2.31633670586674e+18实际条件数为 6.37335273308473e+18结果分析随着矩阵阶数增加,估计值误差开始出现, 时估计条件数与实际值存在误20,1765n差;且条件数很大,Hilbert 矩阵为病态的。解(2)分析:先根据题目要求,利用 和 使 从 5 循环到 30,作出 和随机for( )adA的 ,并计算出 ;然后再利用第一章习题中得到的 和xAxb )(,GausColPUL用列主元 Gauss 消去法求解该方程组,假定计算解为 ,得),(PULbAGausx
12、1x,利用第(1)问所得函数 计算 的一个估计值,利用*r).(Ainvopt1计算 的无穷范数,则 的相对误差估计为inf),(omr,1x,真实相对误差为)/rm(b,(,A.)*ropt(invp ifif。)/rmx,r(x-ff12程序为1 列主元 Gauss 消去法求解该方程组的程序为的 分解:ALUfunction L,U,P=GaussCol(A)n=length(A);for k=1:n-1s,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;if A(k,k)=0A
13、(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);else break;endendL=tril(A);U=triu(A);L=L-diag(diag(L)+diag(ones(1,n); P=eye(n);for i=1:n-1temp=P(i,:);P(i,:)=P(u(i),:);P(u(i),:)=temp;endend高斯消去法解线性方程组function x=Gauss(A,b,L,U,P)if nargin5P=eye(length(A);endn=length(A);b
14、=P*b;for j=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;for j=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_2for n=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); x
15、1=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.3
16、434e-15实际相对误差为 2.8523e-16n=7估计相对误差为 9.882e-16实际相对误差为 1.7941e-16n=8估计相对误差为 4.8733e-14实际相对误差为 1.0891e-14n=9估计相对误差为 2.2282e-14实际相对误差为 3.6143e-15n=10估计相对误差为 1.5622e-14实际相对误差为 3.9702e-15n=11估计相对误差为 1.9668e-14实际相对误差为 5.1566e-15n=12估计相对误差为 4.808e-14实际相对误差为 8.5677e-15n=13估计相对误差为 2.8696e-13实际相对误差为 4.0392e-14
17、n=14估计相对误差为 1.5109e-12实际相对误差为 3.8759e-13n=15估计相对误差为 4.3829e-13实际相对误差为 1.67e-13n=16估计相对误差为 8.7941e-13实际相对误差为 2.6417e-13n=17估计相对误差为 2.4842e-12实际相对误差为 5.8841e-13n=18估计相对误差为 7.6311e-12实际相对误差为 2.4718e-12n=19估计相对误差为 1.9214e-11实际相对误差为 5.9876e-12n=20估计相对误差为 5.612e-11实际相对误差为 1.5802e-11n=21估计相对误差为 1.7181e-11实
18、际相对误差为 2.1433e-12n=22估计相对误差为 1.0565e-11实际相对误差为 2.8952e-12n=23估计相对误差为 6.9651e-12实际相对误差为 1.2037e-12n=24估计相对误差为 3.1487e-10实际相对误差为 1.4479e-10n=25估计相对误差为 9.884e-10实际相对误差为 2.3499e-10n=26估计相对误差为 4.1606e-09实际相对误差为 6.3158e-10n=27估计相对误差为 5.8332e-09实际相对误差为 1.7298e-09n=28估计相对误差为 3.9754e-09实际相对误差为 6.9346e-10n=29估计相对误差为 7.8248e-09实际相对误差为 1.4376e-09n=30估计相对误差为 1.1681e-07实际相对误差为 2.0748e-08结果分析n 较小时估计的较好,随着 n 的增大估计值误差增大5 10 15 20 25 3000.511.522.533.5x 10-8估估估估估估估估估估估估