您好,欢迎访问三七文档
1、证明1xsinx0在[0,1]内有一个根,使用二分法求误差不大于21104的根要迭代多少次并输出每一步的迭代解和迭代误差。解:因为1*2/2/kkkkababxx,4110*212/01k,所以经过计算之后有14k,即需要迭代14次。运用matlab编程法程序如下:functionT1a=0;b=1;fprintf('n||a||b||c\n')fork=1:14c=(a+b)/2;fa=1-a-sin(a);fb=1-b-sin(b);fc=1-c-sin(c);fprintf('%d||%f||%f||%f\n',k,a,b,c);ifabs(fc)(1/2)*10^(-4)r=c;sprintf('therootis:%d',r);elseiffa*fc0b=c;elseiffb*fc0a=c;endendroot=(a+b)/2运行结果如下:n||a||b||c1||0.000000||1.000000||0.5000002||0.500000||1.000000||0.7500003||0.500000||0.750000||0.6250004||0.500000||0.625000||0.5625005||0.500000||0.562500||0.5312506||0.500000||0.531250||0.5156257||0.500000||0.515625||0.5078138||0.507813||0.515625||0.5117199||0.507813||0.511719||0.50976610||0.509766||0.511719||0.51074211||0.510742||0.511719||0.51123012||0.510742||0.511230||0.51098613||0.510742||0.511230||0.51098614||0.510742||0.511230||0.510986root=0.5110二求解方程xex的根,要求5.00x,分别用简单迭代法,迭代法的加速方法:)(1)(11kkkkxxppxfx,以及艾特金方法求解,要求误差应满足|kkxx1|510解:简单迭代法:程序如下:x0=0.5;epsilon=10^(-5);e=1;fprintf('k||xk||error\n');k=1;whileeepsilonx1=exp(-x0);e=abs(x1-x0);x0=x1;k=k+1;fprintf('%d||%f||%f\n',k,x1,e);endx0k||xk||error2||0.606531||0.1065313||0.545239||0.0612914||0.579703||0.0344645||0.560065||0.0196386||0.571172||0.0111087||0.564863||0.0063098||0.568438||0.0035759||0.566409||0.00202910||0.567560||0.00115011||0.566907||0.00065212||0.567277||0.00037013||0.567067||0.00021014||0.567186||0.00011915||0.567119||0.00006716||0.567157||0.00003817||0.567135||0.00002218||0.567148||0.00001219||0.567141||0.000007x0=0.5671迭代法的加速方法:程序如下:x0=0.5;epsilon=10^(-5);e=1;fprintf('k||xk||error\n');k=1;whileeepsilonx11=exp(-x0);x1=x11-p*(x11-x0)/(p-1);e=abs(x0-x1);x0=x1;k=k+1;fprintf('%d||%f||%f\n',k,x1,e);endx0结果如下:k||xk||error2||0.566582||0.0665823||0.567132||0.0005504||0.567143||0.0000115||0.567143||0.000000x0=0.5671艾特金加速迭代法:程序如下:x0=0.5;epsilon=10^(-5);e=1;fprintf('k||xk||error\n');k=1;whileeepsilonx1=exp(-x0);x2=exp(-x1);x00=x0-(x1-x0)^2/(x0-2*x1+x2);e=abs(x0-x00);x0=x00;k=k+1;fprintf('%d||%f||%f\n',k,x1,e);endx0k||xk||error2||0.606531||0.0676243||0.566871||0.0004814||0.567143||0.000000x0=0.56713、分别用单点弦割法和双点弦割法求f(x)x32x210x200的根,要求xk1xk106。解:单点弦割法:(我理解的就是牛顿迭代法,即切线法)f(x)=0在(0,2)内有一个根,且f(x)的二阶导大于0,f(2)0,所以取初值x0=2,利用牛顿迭代公式可求解;程序如下:functionchap2newtoniterx0=2;epsilon=10^(-6);e=1;k=0;fprintf('k||xk||error\n');whileeepsilonx1=phi(x0);e=abs(x1-x0);x0=x1;k=k+1;fprintf('%d||%f||%f\n',k,x1,e);endroot=x1;endfunctiony=phi(x)y=x-(x^3+2*x^2+10*x-20)/(3*x^2+4*x+10);endmatlab运行结果如下:k||xk||error1||1.466667||0.5333332||1.371512||0.0951553||1.368810||0.0027024||1.368808||0.0000025||1.368808||0.000000双点弦割法:程序如下:functionchap2newtoniterx0=1;x1=1.5;epsilon=10^(-6);e=1;k=0;fprintf('k||xk||error\n');whileeepsilonx1=phi(x0);x2=x1-phi(x1)*(x1-x0)/(phi(x1)-phi(x0));e=abs(x2-x1);x1=x2;k=k+1;fprintf('%d||%f||%f\n',k,x1,e);endroot=x2;endfunctiony=phi(x)y=x^3+2*x^2+10*x-20;end4、用牛顿法求解Leonardo方程x32x210x200要求6110kkxx运用matlab编程法程序如下:functionT4x0=0.5;epsilon=10^(-6);e=1;k=0;fprintf('k||xk||error\n');whileeepsilonx1=phi(x0);e=abs(x1-x0);x0=x1;k=k+1;fprintf('%d||%f||%f\n',k,x1,e);endroot=x1;endfunctiony=phi(x)y=x-(x^3+2*(x^2)+10*x-20)/(3*(x^2)+4*x+10);end运行结果如下:k||xk||error1||1.627451||1.1274512||1.386927||0.2405243||1.368903||0.0180244||1.368808||0.0000955||1.368808||0.0000005、利用Gauss消元法求解下列线性代数方程组。1822562172311323114321432143214321xxxxxxxxxxxxxxxx运用matlab编程法程序如下:functionT5%GuasseliminationmethodforsolvingalgebraiclinearequationsA=[11-3-21;-112317;1-26-1;1-22-8];b=[3;1;5;-1];n=size(A,2);%Theeliminationprocess:fork=1:n-1fori=k+1:nl(i,k)=A(i,k)/A(k,k);%inordertosavetime,wecanusej=k+1:n.forj=k:nA(i,j)=A(i,j)-l(i,k)*A(k,j);endb(i)=b(i)-l(i,k)*b(k);endendA%Thesolvingprocessx=zeros(n,1);x(n,1)=b(n)/A(n,n);fori=n-1:-1:1x(i)=(b(i)-sum(A(i,i+1:n).*x(i+1:n,1)'))/A(i,i);endx%comparethedirectsolveinmatlab.y=A\b运行结果如下:A=11.0000-3.0000-2.00001.0000020.0000-1.00008.0000006.0955-0.4000000-7.2625x=0.42110.09570.85640.3678y=0.42110.09570.85640.36786、利用追赶法求解下列线性代数方程组。41x11411x21141x491145050x501解:程序如下:A=zeros(50);L=zeros(50);U=zeros(50);fork=1:49A(k,k+1)=-1;A(k+1,k)=-1;A(k,k)=4;U(k,k)=1;endA(50,50)=4;U(50,50)=1;fork=1:49L(k+1,k)=A(k+1,k);endL(1,1)=A(1,1);U(1,2)=A(1,2)/L(1,1);fork=2:49L(k,k)=A(k,k)-A(k,k-1)*U(k-1,k);U(k,k+1)=A(k,k+1)/L(k,k);endL(50,50)=A(50,50)-L(50,49)*U(49,50);ALUF=ones(50);F=F'Y=(L^(-1))*F;X=(U^(-1))*Y;X求解方程的迭代法:7建立解线性方程组1221112332311321321321xxxxxxxxx的Jacobi和Gauss‐Seidel迭代格式,并输出相应方法迭代10次后的近似解。(1)Jacobi迭代法运用matlab编程法程序如下:functionT7j%useJacobiiterativemethodforfollowingAx=b%CreatedbyLuopingChenforclassofnumericalanalysisA=[11-3-2;-23111;1-22];b=[3;1;-1];%%exactsolutionofAx=bx=A\b%%numericalsolutionbyJacobiiterativemethod:n=size(A,2);%theinitialiterativevalue:x0=zeros(n,1);%======usethematrixform======D=diag(diag(A));%gettheloweranduppertrianglepartofA:L=-tril(A);U=-triu(A);L=L+D;U=U+D;fork=1:10x1=inv(D)*(L+U
本文标题:数值分析pdf
链接地址:https://www.777doc.com/doc-2387452 .html