《微分方程数值解法课程设计-许.doc》由会员分享,可在线阅读,更多相关《微分方程数值解法课程设计-许.doc(9页珍藏版)》请在金锄头文库上搜索。
1、微分方程数值解法课程设计-A组 计算022班3号 许*1. 用复化梯形计算积分解:算法思想:根据复化梯形公式:取步长,有,写出程序,如下所示:N=100;a=0;b=10;h=(b-a)/N;T=zeros(0,N);for j=1:N T(j)=0.5*h*exp(-(a+h*(j-1).2)+exp(-(a+h*j).2) t=sum(T)end运行结果:t = 0.88622. 用Euler、改进的Euler法、梯形法、R-K法解 解:根据算法思想:(1)Euler法 (2)改进的Euler法(3)梯形法(4)R-K法我们可以写出程序如下所示:format long;N=100;h=1/
2、N;%步长U=zeros(1,N+1);%eulerT=zeros(1,N+1);%真解X=zeros(1,N+1);R=zeros(4,N+1);%误差G=zeros(1,N+1);%改进euleO=zeros(1,N+1);%梯形法K=zeros(1,N+1)%R-K法c=zeros(1,4);a=0;for j=2:N+1; X(j)=h*(j-1);endU(1)=1T(1)=1;G(1)=1;X(1)=0;O(1)=1;K(1)=1;for j=1:N U(j+1)=U(j)+h*(U(j)+X(j); %euler法公式 a=G(j)+h*(G(j)+X(j); G(j+1)=G(
3、j)+h/2*(G(j)+X(j)+a+X(j+1); %改进的euler法公式 b=O(j)+h*(O(j)+X(j); for i=1:10 O(j+1)=O(j)+h/2*(G(j)+X(j)+b+X(j+1); %梯形法公式 b=O(j+1);endc(1)=K(j)+X(j);c(2)=K(j)+h/2*c(1)+(X(j)+h/2);c(3)=K(j)+h/2*c(2)+(X(j)+h/2);c(4)=K(j)+h*c(3)+(X(j)+h);K(j+1)=K(j)+h/6*(c(1)+2*c(2)+2*c(3)+c(4);%四阶R-K法公式 T(j+1)=-X(j+1)-1+2*
4、exp(X(j+1); %真实值 R(1,j+1)=U(j+1)-T(j+1); %EULER法误差 R(2,j+1)=G(j+1)-T(j+1); %改进的EULER法误差 R(3,j+1)=O(j+1)-T(j+1); %梯形法误差 R(4,j+1)=K(j+1)-T(j+1); %四阶R-K法误差end真实值T:11.01011.02041.03091.04161.05251.06371.0751.08661.09831.11031.12261.1351.14771.16051.17371.1871.20061.21441.22851.24281.25741.27221.28721.30
5、251.31811.33391.34991.36631.38291.39971.41691.43431.45191.46991.48811.50671.52551.54461.5641.58361.60361.62391.64451.66541.68661.70811.731.75211.77461.79741.82061.84411.86791.8921.91651.94131.96651.99212.0182.04422.07092.09792.12522.1532.18112.20962.23852.26782.29742.32752.3582.38892.42022.45192.484
6、2.51662.54952.58292.61682.65112.68582.7212.75662.79272.82932.86632.90382.94182.98033.01923.05863.09863.1393.183.22143.26343.30593.34893.39253.4366欧拉法U值:11.011.02021.03061.04121.0521.0631.07431.08571.09741.10921.12131.13371.14621.15891.17191.18521.19861.21231.22621.24041.25481.26941.28431.29951.31491
7、.33051.34641.36261.3791.39571.41271.42991.44741.46521.48321.50151.52021.53911.55821.57771.59751.61761.6381.65861.67961.70091.72251.74451.76671.78931.81221.83541.85891.88281.9071.93161.95651.98182.00742.03342.05972.08642.11352.14092.16872.19692.22552.25442.28382.31352.34372.37422.40512.43652.46832.50
8、042.5332.56612.59952.63342.66782.70252.73782.77342.80962.84622.88322.92082.95882.99733.03623.07573.11573.15613.19713.23853.28053.3233.36613.4096改进的欧拉法G值:11.01011.02041.03091.04161.05251.06371.0751.08661.09831.11031.12261.1351.14771.16051.17371.1871.20061.21441.22851.24281.25731.27211.28721.30251.318
9、1.33381.34991.36621.38281.39971.41681.43421.45191.46991.48811.50661.52551.54461.56391.58361.60361.62391.64451.66541.68661.70811.731.75211.77461.79741.82061.8441.86781.8921.91651.94131.96651.9922.01792.04422.07082.09782.12522.15292.1812.20952.23842.26772.29742.32752.35792.38882.42012.45182.48392.5165
10、2.54952.58292.61672.6512.68582.72092.75662.79272.82922.86632.90382.94172.98023.01913.05863.09853.13893.17993.22133.26333.30583.34883.39243.4365梯形法O值:11.01011.02041.03091.04161.05251.06371.0751.08661.09841.11031.12261.1351.14771.16061.17371.1871.20061.21441.22851.24281.25741.27221.28721.30251.31811.3
11、3391.34991.36631.38291.39971.41691.43431.45191.46991.48811.50671.52551.54461.5641.58371.60361.62391.64451.66541.68661.70821.731.75221.77461.79751.82061.84411.86791.8921.91651.94141.96651.99212.0182.04422.07092.09792.12522.1532.18112.20962.23852.26782.29742.32752.3582.38892.42022.45192.4842.51662.549
12、52.5832.61682.65112.68582.7212.75672.79272.82932.86632.90382.94182.98033.01923.05873.09863.1393.183.22143.26343.30593.34893.39253.4366R-K法K值:11.01011.02041.03091.04161.05251.06371.0751.08661.09831.11031.12261.1351.14771.16051.17371.1871.20061.21441.22851.24281.25741.27221.28721.30251.31811.33391.349
13、91.36631.38291.39971.41691.43431.45191.46991.48811.50671.52551.54461.5641.58361.60361.62391.64451.66541.68661.70811.731.75211.77461.79741.82061.84411.86791.8921.91651.94131.96651.99212.0182.04422.07092.09792.12522.1532.18112.20962.23852.26782.29742.32752.3582.38892.42022.45192.4842.51662.54952.58292
14、.61682.65112.68582.7212.75662.79272.82932.86632.90382.94182.98033.01923.05863.09863.1393.183.22143.26343.30593.34893.39253.4366误差R值:第一组0-0.00010033-0.00020268-0.00030707-0.00041353-0.00052209-0.00063279-0.00074566-0.00086072-0.00097802-0.0010976-0.0012194-0.0013436-0.0014702-0.0015992-0.0017306-0.0018645-