📄 na53test.m
字号:
%function na53test
[x1,y1]=rk_wjl('funtest3',0,2,1,0.1);
[x2,y2]=adams_wjl1('funtest3',0,2,1,0.1);
ye=feval('exact53',x1);
err1=y1-ye;
%err1=abs(y1-ye);
%err2=y2-ye;
err2=abs(y2-ye);
figure(1)
fprintf('%5.3f\n',x1(1:10))
fprintf('%+2.1e\n',err1(1:10))
fprintf('%+2.1e\n',err2(1:10))
plot(x1,err1,x1,err2)
legend('Runge-Kutta','Adams')
xlabel('x')
ylabel('y')
title('step=0.1,Error of problem3 with Runge-Kutta,Adams')
[x1,y1]=rk_wjl('funtest3',0,2,1,0.01);
[x2,y2]=adams_wjl1('funtest3',0,2,1,0.01);
ye=feval('exact53',x1);
fprintf('%25.15f\n',y1(1:10))
fprintf('%25.15f\n',y2(1:10))
fprintf('%25.15f\n',x1(1:10))
fprintf('%25.15f\n',ye(1:10))
err1=y1-ye;
%err1=abs(y1-ye);
err2=y2-ye;
%err2=abs(y2-ye);
figure(2)
fprintf('%+2.1e\n',err1(1:10))
fprintf('%+2.1e\n',err2(1:10))
fprintf('%5.3f\n',x1(1:10))
plot(x1,err1,x1,err2)
legend('Runge-Kutta','Adams')
xlabel('x')
ylabel('y')
title('step=0.01,Error of problem3 with Runge-Kutta,Adams')
[x1,y1]=rk_wjl('funtest3',0,2,1,0.001);
[x2,y2]=adams_wjl1('funtest3',0,2,1,0.001);
ye=feval('exact53',x1);
err1=y1-ye;
%err1=abs(y1-ye);
%err2=y2-ye;
err2=abs(y2-ye);
figure(3)
fprintf('%+2.1e\n',err1(1:10))
fprintf('%+2.1e\n',err2(1:10))
fprintf('%5.3f\n',x1(1:10))
plot(x1,err1,x1,err2)
legend('Runge-Kutta','Adams')
xlabel('x')
ylabel('y')
title('step=0.001,Error of problem3 with Runge-Kutta,Adams')
[x1,y1]=rk_wjl('funtest3',0,30,1,0.1);
[x2,y2]=adams_wjl1('funtest3',0,30,1,0.1);
ye=feval('exact53',x1);
err1=y1-ye;
%err1=abs(y1-ye);
err2=y2-ye;
%err2=abs(y2-ye);
figure(4)
fprintf('%5.3f\n',x1(1:10))
fprintf('%+2.1e\n',err1(1:10))
fprintf('%+2.1e\n',err2(1:10))
plot(x1,err1,x1,err2)
legend('Runge-Kutta','Adams')
xlabel('x')
ylabel('y')
title('step=0.1,Range=0..30,Error of problem3 with Runge-Kutta,Adams')
figure(5)
plot(x1,y1,x2,y2,x1,ye)
legend('Runge-Kutta','Adams','exact')
xlabel('x')
ylabel('y')
title('step=0.1,Range=0..30,problem3 with Runge-Kutta,Adams')
[x1,y1]=rk_wjl('funtest3',0,30,1,0.01);
[x2,y2]=adams_wjl1('funtest3',0,30,1,0.01);
ye=feval('exact53',x1);
err1=y1-ye;
%err1=abs(y1-ye);
err2=y2-ye;
%err2=abs(y2-ye);
figure(6)
fprintf('%5.3f\n',x1(1:10))
fprintf('%+2.1e\n',err1(1:10))
fprintf('%+2.1e\n',err2(1:10))
plot(x1,err1,x1,err2)
legend('Runge-Kutta','Adams')
xlabel('x')
ylabel('y')
title('step=0.01,Range=0..30,Error of problem3 with Runge-Kutta,Adams')
figure(7)
plot(x1,y1,x2,y2,x1,ye)
legend('Runge-Kutta','Adams','exact')
xlabel('x')
ylabel('y')
title('step=0.01,Range=0..30,problem3 with Runge-Kutta,Adams')
%time compare
tic;
[x1,y1]=rk_wjl('funtest3',0,2,1,0.001);
t1=toc;
tic;
[x2,y2]=adams_wjl1('funtest3',0,2,1,0.001);
t2=toc;
t1,t2
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -