您好,欢迎访问三七文档
当前位置:首页 > 建筑/环境 > 工程监理 > 《应用计算方法教程》大作业
《应用计算方法教程》作业姓名:**学号:S2017****专业:****学院:机械工程学院联系方式:***********任课教师:丁军作业一.用任意方法求解七阶方程-5+22x-12x2+x3+13x4+10x5-7x6-4x7牛顿迭代法:y=@(x)4*x^7+7*x^6-10*x^5-13*x^4-x^3+12*x^2-22*x+5;s=@(m)28*m^6+42*m^5-50*m^4-52*m^3-3*m^2+24*m-22;p0=0;N=1000;Tol=0.001;fork=1:Np1=p0-y(p0)/s(p0);ifabs(p1-p0)Tolp0=p1;elsebreakendenddisp(p1);disp(k)作业二.实验4-2合理利用LU分解法(使用列选主元可恰当加分)或追赶法求解下列方程组:程序:A=[1.3,-1,-1,2.4,-3.4;2.4,-1,-1,1.4,3.7;2,1,-2,3.6,6.8;2.5,-1,4,3,6.6;1.5,-1,-1,5.3,2.8];b=[4.2;6.3;5.5;3.6;6.2];L=eye(5);U(1,:)=A(1,:);y=[0;0;0];x=[0;0;0];fork=2:5ifU(k-1,k-1)==0{disp('分解失败');Return}endL(k:5,k-1)=A(k:5,k-1)/U(k-1,k-1)U(k,k:5)=A(k,k:5)-L(k,1:k-1)*U(1:k-1,k:5)ifk5A(k+1:5,k)=A(k+1:5,k)-L(k+1:5,1:k-1)*U(1:k-1,k);endendL1=inv(L);y=L1*b;U1=inv(U);x=U1*y;disp(L);disp(U);disp(x);结果:作业三.实验4-34-3.实验目的:考察Holert矩阵的性态,了解病态方程组求解。实验内容:生成hilbert矩阵:。计算的条件数,观察其变化。分别应用LU分解法与LU分解迭代求精法求解方程组。将两种方法所得结果进行比较。1)计算的条件数算法实现:%n=5:10clear;clc;formatratforn=5:10fori=1:nforj=1:nH(i,j)=1/(i+j-1);endenddisp(H)cond(H,1)end运算结果:11/21/31/41/51/21/31/41/51/61/31/41/51/61/71/41/51/61/71/81/51/61/71/81/9Cond1=943656Cond1=29070279Cond1=985194888Cond1=33872789100Cond1=1099649467886Cond1=3535336877175111/21/31/41/51/61/71/81/91/101/21/31/41/51/61/71/81/91/101/111/31/41/51/61/71/81/91/101/111/121/41/51/61/71/81/91/101/111/121/131/51/61/71/81/91/101/111/121/131/141/61/71/81/91/101/111/121/131/141/151/71/81/91/101/111/121/131/141/151/161/81/91/101/111/121/131/141/151/161/171/91/101/111/121/131/141/151/161/171/181/101/111/121/131/141/151/161/171/181/19观察结论:矩阵的条件数越来越大,而且远远大于1,这是一个病态问题1)LU分解法算法实现:%n=5:10clear;clc;n=10fori=1:nforj=1:nH(i,j)=1/(i+j-1);endenddisp(H)cond(H,1)formatshort;n=size(H);L=eye(n);U(1,:)=H(1,:);fork=2:nifU(k-1,k-1)==0disp('分解失败');returnendL(k:n,k-1)=H(k:n,k-1)/U(k-1,k-1);U(k,k:n)=H(k,k:n)-L(k,1:k-1)*U(1:k-1,k:n);ifknH(k+1:n,k)=H(k+1:n,k)-L(k+1:n,1:k-1)*U(1:k-1,k);endendB([1:10],1)=1;Y=L\B;LUX=U\Y运行结果:L=1.00000000000000.50001.0000000000000.33331.00001.000000000000.25000.90001.50001.00000000000.20000.80001.71432.00001.0000000000.16670.71431.78572.77782.50001.000000000.14290.64291.78573.33334.09093.00001.00000000.12500.58331.75003.71215.56825.65383.50001.0000000.11110.53331.69703.95966.85318.61547.46674.00001.000000.10000.49091.63644.11197.930111.630812.60009.52944.50001.0000U=1.00000.50000.33330.25000.20000.16670.14290.12500.11110.100000.08330.08330.07500.06670.05950.05360.04860.04440.0409000.00560.00830.00950.00990.00990.00970.00940.00910000.00040.00070.00100.00120.00130.00140.001500000.00000.00010.00010.00010.00020.0002000000.00000.00000.00000.00000.00000000000.00000.00000.00000.000000000000.00000.00000.0000000000000.00000.00000000000000.0000X=1.0e+06*-0.00000.0010-0.02380.2402-1.26113.7834-6.72617.0007-3.93790.92372)LU分解迭代求精法算法实现:%n=5:10clear;clc;n=10;fori=1:nforj=1:nH(i,j)=1/(i+j-1);endendformatshort;n=size(H);L=eye(n);U(1,:)=H(1,:);tol=10^(-3);fork=2:nifU(k-1,k-1)==0disp('分解失败');returnendL(k:n,k-1)=H(k:n,k-1)/U(k-1,k-1);U(k,k:n)=H(k,k:n)-L(k,1:k-1)*U(1:k-1,k:n);ifknH(k+1:n,k)=H(k+1:n,k)-L(k+1:n,1:k-1)*U(1:k-1,k);endendB([1:10],1)=1;Y=L\B;X=U\Y;r=B-H*X;Y=L\r;w=U\Y;formatlongwhilenorm(w)tolr=B-H*X;Y=L\r;w=U\Y;X=X+w;endX运算结果:X=1.0e+06*-0.0000099983463550.000989857965323-0.0237569902910640.240212759410420-1.2611305603384353.783425339621443-6.7261397788656957.000720697677755-3.9379270271364350.923715699219681结果分析:对于同一复杂程度的方程组,LU分解迭代求精法所得的解较LU分解法所得到的解的精确度更高。作业四.实验5-1分别用Jacobi、Seidel、Sor(错误!未找到引用源。=0.8,1.1,1.2,1.3,1.4,1.5)迭代求解下面的方程组,并做结果分析。初值错误!未找到引用源。,精度要求:错误!未找到引用源。错误!未找到引用源。。Jacobi:A=[12.3,-2,-1,3.4,-3.7;1.4,9,-3,2.4,2.7;2.1,1,8,2.6,5.8;3.5,-2.1,1,13,4.6;2.5,-1,-2,5.3,14.8];b=[4.8;2.3;2.5;3.6;2.2];X0=[0;0;0;0;0];X=X0;K=1;whileK=30fori=1:5X(i)=(b(i)-A(i,:)*X0)/A(i,i)+X0(i);endifnorm(X-X0)/X0.00001disp(X);disp(K);return;endK=K+1;X0=X;end结果:Seidel:A=[12.3,-2,-1,3.4,-3.7;1.4,9,-3,2.4,2.7;2.1,1,8,2.6,5.8;3.5,-2.1,1,13,4.6;2.5,-1,-2,5.3,14.8];b=[4.8;2.3;2.5;3.6;2.2];X0=[0;0;0;0;0];X=X0;K=1;whileK=20fori=1:5X(i)=(b(i)-A(i,:)*X)/A(i,i)+X(i);endifnorm(X-X0)/X0.00001disp(X);disp(K);return;endK=K+1;X0=X;enddisp('发散');结果:SOR:A=[12.3,-2,-1,3.4,-3.7;1.4,9,-3,2.4,2.7;2.1,1,8,2.6,5.8;3.5,-2.1,1,13,4.6;2.5,-1,-2,5.3,14.8];b=[4.8;2.3;2.5;3.6;2.2];X0=[0;0;0;0;0];X=X0;K=1;w=[0.8,1.1,1.2,1.3,1.4,1.5];forj=1:6m=w(j);whileK=20fori=1:5X(i)=m*(b(i)-A(i,:)*X)/A(i,i)+X(i);endifnorm(X-X0,inf)/norm(X,inf)0.00001disp(X);disp(K);break;endK=K+1;X0=X;endend结果:w=0.8w=1.1w=1.2w=1.2作业五.实验7-2试验目的:观察Larange的插值的Ruange现象,了解若能采用合适的结点分布,则可以避免Runge现象,熟悉三次样条插值。试验内容:对于函数进行larange插值。取不同的等分数n=5,10,将区间[-1,1]n等分,取等距节点。把和5次,10次插值多项式的曲线画在同一张图上比较。再进行Chebyshev结点cos进行Larange插值,把和Chebyshev结点的10次插值多项式的曲线画在同一张图上。试验一:1.算法实现%原函数图像figure(1)x=-1:0.01:1;y=1./(1+25.*x.^2);plot(x,y,'k')gridon;holdon;%Lagrange插值yy=0;n=5;x=-1:2/n:1;y=1./(1+25.*x.^2);xx=-1:0.01:1;fork=1:n+1t=1;fori=1:n+1ifi~=k;t=t.*(xx-x(i))/(x(k)-x(i));endendyy=yy+t*y(k);endplot(xx,yy,'g-')holdonn=10;yy=0;x=-1:2/n:1;y=1./(1+25.*x.^2);xx=-1:0.01:1;fork=1:n+1t=1;fori=1:n+1ifi~=k;t=t.*(xx-x(i))/(x(k)-x(i));endendyy=yy+t*y(k);endplot(x
本文标题:《应用计算方法教程》大作业
链接地址:https://www.777doc.com/doc-4870683 .html