您好,欢迎访问三七文档
1实验十一、编程并在计算机上调试修改运行1.利用公式计算0!nxnxen2.利用公式计算210sin(21)!nnxxn二、阅读理解下列程序,并在计算机上运行1.jzhexp.m%利用ex的展开式计算矩阵函数eA的值function[E,k]=jzhexp(A);%A是方阵E=zeros(size(A));F=eye(size(A));k=1;whilenorm(F,1)0E=E+F;F=A*F/k;k=k+1;end2.xjfdd.m%x0,x为初值,w为精度,n为最大迭代次数function[a,k]=xjfdd(x0,x,w,n)a(1:2)=[x0,x];fork=1:niff(x)-f(x0)==0disp('分母为零')breakendy=x-(x-x0)*f(x)/(f(x)-f(x0));a(k+2)=y;ifabs(y-x)w2x=y;elsebreakendendifk==ndisp('迭代失败')endfunctiony=f(x)%子函数y=x*exp(x)-1;3.kxjfdd.m%x0,x为初值,w为精度,n为最大迭代次数function[a,k]=kxjfdd(x0,x1,w,n)a(1:2)=[x0,x1];fork=1:niff(x1)-f(x0)==0disp('分母为零')breakendy=x1-(x1-x0)*f(x1)/(f(x1)-f(x0));a(k+2)=y;ifabs(y-x1)wx0=x1;x1=y;elsebreakendendifk==ndisp('迭代失败')end3functiony=f(x)%子函数y=x*exp(x)-1;三、选做题:修改单点弦截法程序dxjf.m,并在计算机上运行functionx2=dxjf(x0,x1,w,N)k=1;whilek~=Nifg(x1)==0x2='分母为零'endx2=x1-f(x1)/g(x1);ifabs(x2-x1)wbreakendk=k+1;x1=x2;endifk==Nx2='迭代失败'endfunctiony=f(x)%子函数y=4*cos(x)-exp(x);functiony=g(x)%子函数y=(f(x)-f(x0))/(x-x0);一、1、functiony=f(x,n)y=0;fork=0:ny=y+(x^k)/(jiecheng(k));endfunctiony1=jiecheng(n)4y1=1;ifn==0y1=1;elsefork=1:ny1=y1*k;endendf(1,10)ans=2.718281801146385f(2,10)ans=7.388994708994708f(1,100)ans=2.718281828459046f(0,10)ans=12、functiony=f(x,n)y=0;fork=1:ny=y+((-1)^(k-1))*x^(2*k-1)/(jiecheng(2*k-1));endfunctiony1=jiecheng(a)y1=1;5ifa==0y1=1;elsefork=1:ay1=y1*k;endendf(1,10)ans=0.841470984807897f(2,10)ans=0.909297426825641f(pi/2,100)ans=1.000000000000000二、1、A=[12;21];[E,k]=jzhexp(A)E=10.2267081821795529.8588287410081099.85882874100810910.226708182179552k=225A=[10;01];6[E,k]=jzhexp(A)E=2.718281828459046002.718281828459046k=1792、[a,k]=xjfdd(0,1,1e-4,100)a=Columns1through301.0000000000000000.367879441171442Columns4through60.6922006275553470.5004735005636370.606243535085597Columns7through90.5453957859750270.5796123355033790.560115461361089Columns10through120.5711431150801770.5648793473910490.568428725029061Columns13through150.5664147331468830.5675566373282840.566908911921495Columns16through180.5672762321755700.5670678983907880.567186050099357Column190.5671190400572157k=17[a,k]=xjfdd(0.5,1,1e-4,100)a=Columns1through30.5000000000000001.0000000000000000.546369237877742Columns4through60.5683224025550880.5670769085227040.567147029318608k=43、[a,k]=kxjfdd(0.5,1,1e-4,100)a=Columns1through30.5000000000000001.0000000000000000.546369237877742Columns4through60.5607946775818430.5672523630241860.567142721988679Column70.567143290359005k=85[a,k]=kxjfdd(0.5,6,1e-4,100)a=Columns1through30.5000000000000006.0000000000000000.500399221880030Columns4through60.5007961702444020.5709499966081740.566931787132861Columns7through80.5671426318091890.567143290523883k=6三、
本文标题:计算方法实验10
链接地址:https://www.777doc.com/doc-5491963 .html