资源描述
<p><span id="_baidu_bookmark_start_0" style="display: none; line-height: 0px;"></span>(1) 估计5到20阶Hilbert矩阵得范数条件数
(2) 设,先随机地选取,并计算出;然后再用列主元Gauss消去法求解该方程组,假定计算解为。试对n从5到30估计计算解得精度,并且与真实相对误差作比较。
解(1)分析:利用使从5循环到20,利用函数得到Hilbert矩阵;先将算法2、5、1编制成通用得子程序,利用算法2、5、1编成得子程序,对求解,得到得一个估计值;再利用得到;则条件数。
另,矩阵得范数条件数可由直接算出,两者可进行比较。
程序为
1 算法2、5、1编成得子程序
function v=opt(B)
k=1;
n=length(B);
x=1、/n*ones(n,1);
while k==1
w=B*x;
v=sign(w);
z=B'*v;
if norm(z,inf)<=z 2="" 67="" 422="" 5079="" 7717="" 943656="" x="zeros(n,1);" v="opt(B);" k="1;" else="" end="" ex2_1="" for="" n="11" a="hilb(n);" b="inv(A、');" k1="v*norm(A,inf);" k2="cond(A,inf);" 0028="" 1232433965549344="" warning:="" matrix="" is="" close="" to="" singular="" or="" badly="" results="" may="" be="" rcond="2、547634e-17、"> In ex2_1 at 3
Warning: Matrix is close to singular or badly scaled、 Results may be
inaccurate、 RCOND = 2、547634e-17、
> In cond at 47
In ex2_1 at 6
n=12
估计条件数为3、9245e+16
实际条件数为3、9245e+16
Warning: Matrix is close to singular or badly scaled、 Results may be
inaccurate、 RCOND = 7、847381e-19、
> In ex2_1 at 3
Warning: Matrix is close to singular or badly scaled、 Results may be
inaccurate、 RCOND = 7、847381e-19、
> In cond at 47
In ex2_1 at 6
n=13
估计条件数为1、2727e+18
实际条件数为1、2727e+18
Warning: Matrix is close to singular or badly scaled、 Results may be
inaccurate、 RCOND = 2、246123e-18、
> In ex2_1 at 3
Warning: Matrix is close to singular or badly scaled、 Results may be
inaccurate、 RCOND = 2、246123e-18、
> In cond at 47
In ex2_1 at 6
n=14
估计条件数为4、8374e+17
实际条件数为4、8374e+17
Warning: Matrix is close to singular or badly scaled、 Results may be
inaccurate、 RCOND = 8、491876e-19、
> In ex2_1 at 3
Warning: Matrix is close to singular or badly scaled、 Results may be
inaccurate、 RCOND = 8、491876e-19、
> In cond at 47
In ex2_1 at 6
n=15
估计条件数为4、6331e+17
实际条件数为5、234289848563619e+17
Warning: Matrix is close to singular or badly scaled、 Results may be
inaccurate、 RCOND = 9、137489e-19、
> In ex2_1 at 3
Warning: Matrix is close to singular or badly scaled、 Results may be
inaccurate、 RCOND = 9、137489e-19、
> In cond at 47
In ex2_1 at 6
n=16
估计条件数为8、3166e+17
实际条件数为8、3167e+17
Warning: Matrix is close to singular or badly scaled、 Results may be
inaccurate、 RCOND = 6、244518e-19、
> In ex2_1 at 3
Warning: Matrix is close to singular or badly scaled、 Results may be
inaccurate、 RCOND = 6、244518e-19、
> In cond at 47
In ex2_1 at 6
n=17
估计条件数为1、43e+18
实际条件数为1、43e+18
Warning: Matrix is close to singular or badly scaled、 Results may be
inaccurate、 RCOND = 4、693737e-19、
> In ex2_1 at 3
Warning: Matrix is close to singular or badly scaled、 Results may be
inaccurate、 RCOND = 4、693737e-19、
> In cond at 47
In ex2_1 at 6
n=18
估计条件数为2、5551e+18
实际条件数为2、8893e+18
Warning: Matrix is close to singular or badly scaled、 Results may be
inaccurate、 RCOND = 4、264685e-19、
> In ex2_1 at 3
Warning: Matrix is close to singular or badly scaled、 Results may be
inaccurate、 RCOND = 4、264685e-19、
> In cond at 47
In ex2_1 at 6
n=19
估计条件数为2、411858563109357e+18
实际条件数为2、411858563109357e+18
Warning: Matrix is close to singular or badly scaled、 Results may be
inaccurate、 RCOND = 1、351364e-19、
> In ex2_1 at 3
Warning: Matrix is close to singular or badly scaled、 Results may be
inaccurate、 RCOND = 1、351364e-19、
> In cond at 47
In ex2_1 at 6
n=20
估计条件数为2、31633670586674e+18
实际条件数为6、37335273308473e+18
结果分析
随着矩阵阶数增加,估计值误差开始出现,时估计条件数与实际值存在误差;且条件数很大,Hilbert矩阵为病态得。
解(2)分析:先根据题目要求,利用与使从5循环到30,作出与随机得,并计算出;然后再利用第一章习题中得到得与用列主元Gauss消去法求解该方程组,假定计算解为,得,利用第(1)问所得函数计算得一个估计值,利用计算得无穷范数,则得相对误差估计为,真实相对误差为。
程序为
1 列主元Gauss消去法求解该方程组得程序为
得分解:
function [L,U,P]=GaussCol(A)
n=length(A);
for k=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;
if A(k,k)~=0
A(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;
end
end
L=tril(A);
U=triu(A);
L=L-diag(diag(L))+diag(ones(1,n));
P=eye(n);
for i=1:n-1
temp=P(i,:);
P(i,:)=P(u(i),:);
P(u(i),:)=temp;
end
end
高斯消去法解线性方程组
function x=Gauss(A,b,L,U,P)
if nargin<5
P=eye(length(A));
end
n=length(A);
b=P*b;
for j=1:n-1
b(j)=b(j)/L(j,j);
b(j+1:n)=b(j+1:n)-b(j)*L(j+1:n,j);
end
b(n)=b(n)/L(n,n);
y=b;
for j=n:-1:2
y(j)=y(j)/U(j,j);
y(1:j-1)=y(1:j-1)-y(j)*U(1:j-1,j);
end
y(1)=y(1)/U(1,1);
x=y;
end
2 问题(2)求解ex2_2
for n=5:30
A=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;
end
plot(5:30,y1,5:30,y2)
legend('估计相对误差','实际相对误差')
计算结果为
n=5
估计相对误差为2、8265e-15
实际相对误差为3、1615e-16
n=6
估计相对误差为3、3434e-15
实际相对误差为2、8523e-16
n=7
估计相对误差为9、882e-16
实际相对误差为1、7941e-16
n=8
估计相对误差为4、8733e-14
实际相对误差为1、0891e-14
n=9
估计相对误差为2、2282e-14
实际相对误差为3、6143e-15
n=10
估计相对误差为1、5622e-14
实际相对误差为3、9702e-15
n=11
估计相对误差为1、9668e-14
实际相对误差为5、1566e-15
n=12
估计相对误差为4、808e-14
实际相对误差为8、5677e-15
n=13
估计相对误差为2、8696e-13
实际相对误差为4、0392e-14
n=14
估计相对误差为1、5109e-12
实际相对误差为3、8759e-13
n=15
估计相对误差为4、3829e-13
实际相对误差为1、67e-13
n=16
估计相对误差为8、7941e-13
实际相对误差为2、6417e-13
n=17
估计相对误差为2、4842e-12
实际相对误差为5、8841e-13
n=18
估计相对误差为7、6311e-12
实际相对误差为2、4718e-12
n=19
估计相对误差为1、9214e-11
实际相对误差为5、9876e-12
n=20
估计相对误差为5、612e-11
实际相对误差为1、5802e-11
n=21
估计相对误差为1、7181e-11
实际相对误差为2、1433e-12
n=22
估计相对误差为1、0565e-11
实际相对误差为2、8952e-12
n=23
估计相对误差为6、9651e-12
实际相对误差为1、2037e-12
n=24
估计相对误差为3、1487e-10
实际相对误差为1、4479e-10
n=25
估计相对误差为9、884e-10
实际相对误差为2、3499e-10
n=26
估计相对误差为4、1606e-09
实际相对误差为6、3158e-10
n=27
估计相对误差为5、8332e-09
实际相对误差为1、7298e-09
n=28
估计相对误差为3、9754e-09
实际相对误差为6、9346e-10
n=29
估计相对误差为7、8248e-09
实际相对误差为1、4376e-09
n=30
估计相对误差为1、1681e-07
实际相对误差为2、0748e-08
结果分析
n较小时估计得较好,随着n得增大估计值误差增大</p><!--=z-->
展开阅读全文