欢迎来到天天文库
浏览记录
ID:21318264
大小:131.30 KB
页数:4页
时间:2018-10-21
《计算方法算法的数值稳定性实验报告》由会员上传分享,免费在线阅读,更多相关内容在学术论文-天天文库。
1、专业序号_姓名日期实验1算法的数值稳定性实验【实验目的】1.掌握用MATLAB语言的编程训练,初步体验算法的软件实现;2.通过对稳定算法和不稳定算法的结果分析、比较,深入理解算法的数值稳定性及其重要性。【实验内容】1.计算积分,(nH-dx(n=0,l,2……,10)(x+“)其中a为参数,分别对a=0.05及a=15按下列两种方案计算,列出其结果,并对其可靠性,说明原因。12.方案一用递推公式(n=l,2,••••••,10)递推初值可rh积分直接得/=ln(3.方案二用递推公式n-l根据估计式(
2、6Z+1)(Z2+1)annZ2+1当03、eglobalnaN=20;%计算N个值a=0.05;%或者a=15%%%%[方案I]用递推公式%I(k)=-a*I(k-l)+1/k%10=log((a+l)/a);%初值I=zeros(N,1);%创建Nx1矩阵(即列向量),元素全为零1(1)=-a*IO+l;fork=2:NI(k)=-a*I(k-l)+l/k;end%%%%[方案TT]用递推公式%I(k-l)=(-I(k)+1/k)/a%11=zeros(N,1);ifa>=N/(N+1)11(N)=(2*a+1)/(2*a*(a+1)*(4、N+1));elseII(N)=(l/(a+l)/(N+l)+l/N)/2;endfork=N:-l:2Il(k-l)=(-II(k)+l/k)/a;end%%%%调用matlab高精度数值积分命令quadl计算以便比较III=zeros(N,1):fork=1:Nn=k;IIT(k)=quadl(@f,0,1);end%%%%敁示计算结果clcfprintf(*方案I结果方案II結果精确值’)fork=1:N,fprintfCl(%2.Of)%17.7f%17.7f%17.7f’,k,I(5、k),II(k),III(k))end%%functiony=f(x)%定义函数globalna%参量n为全局变量y=x."n./(a+x);%★注意:这里一定要’点’运算return%%/1/—/1/1/1/1/—/lz1/m3)4)5)6)7)8)9)10ll121314151617181920方案I结果0.84777390.45761130.31045280.23447740.18827610.15725290.13499450.11825030.10519860.09476、4010.08617210.07902470.07297180.06778000.06327770.05933610.05585670.05276270.04999340.04750030.84777390.45761130.31045280.23447760.18827610.15725290.13499450.11825030.10519860.09474010.08617240.07902470.07297180.06778000.06327770.05933610.05585670.05277、6270.04999340.0475003【运行结果如下I当a=0.05方案8、9、结果精确值-919648916620722180000.000000045982445831036109000.0000000-2299122291551805700.0000000114956114577590290.0000000-5747805728879515.0000000287390286443975.9400000-14369514322198.6540000718475716110.0577400-35910、23785805.39177701796189290.3695889-89809464.42757044490473.3047119-224523.588312511226.2508442-561.245875528.1247938-1.34741620.12292640.04648530.0476757当a=15方案I结果方案II结果精确值1(1)0.03192220.03192220.03192221(2)0.02116730.02116730.02116731(
3、eglobalnaN=20;%计算N个值a=0.05;%或者a=15%%%%[方案I]用递推公式%I(k)=-a*I(k-l)+1/k%10=log((a+l)/a);%初值I=zeros(N,1);%创建Nx1矩阵(即列向量),元素全为零1(1)=-a*IO+l;fork=2:NI(k)=-a*I(k-l)+l/k;end%%%%[方案TT]用递推公式%I(k-l)=(-I(k)+1/k)/a%11=zeros(N,1);ifa>=N/(N+1)11(N)=(2*a+1)/(2*a*(a+1)*(
4、N+1));elseII(N)=(l/(a+l)/(N+l)+l/N)/2;endfork=N:-l:2Il(k-l)=(-II(k)+l/k)/a;end%%%%调用matlab高精度数值积分命令quadl计算以便比较III=zeros(N,1):fork=1:Nn=k;IIT(k)=quadl(@f,0,1);end%%%%敁示计算结果clcfprintf(*方案I结果方案II結果精确值’)fork=1:N,fprintfCl(%2.Of)%17.7f%17.7f%17.7f’,k,I(
5、k),II(k),III(k))end%%functiony=f(x)%定义函数globalna%参量n为全局变量y=x."n./(a+x);%★注意:这里一定要’点’运算return%%/1/—/1/1/1/1/—/lz1/m3)4)5)6)7)8)9)10ll121314151617181920方案I结果0.84777390.45761130.31045280.23447740.18827610.15725290.13499450.11825030.10519860.0947
6、4010.08617210.07902470.07297180.06778000.06327770.05933610.05585670.05276270.04999340.04750030.84777390.45761130.31045280.23447760.18827610.15725290.13499450.11825030.10519860.09474010.08617240.07902470.07297180.06778000.06327770.05933610.05585670.0527
7、6270.04999340.0475003【运行结果如下I当a=0.05方案
8、
9、结果精确值-919648916620722180000.000000045982445831036109000.0000000-2299122291551805700.0000000114956114577590290.0000000-5747805728879515.0000000287390286443975.9400000-14369514322198.6540000718475716110.0577400-359
10、23785805.39177701796189290.3695889-89809464.42757044490473.3047119-224523.588312511226.2508442-561.245875528.1247938-1.34741620.12292640.04648530.0476757当a=15方案I结果方案II结果精确值1(1)0.03192220.03192220.03192221(2)0.02116730.02116730.02116731(
此文档下载收益归作者所有