Home > K25104 > ODEs > explicit_RK_script_1.m

explicit_RK_script_1

PURPOSE ^

Usage example for explicit_RK

SYNOPSIS ^

This is a script file.

DESCRIPTION ^

 Usage example for explicit_RK
 employing the original Runge-Kutta method

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 % Usage example for explicit_RK
0002 % employing the original Runge-Kutta method
0003 
0004 f = @(t,y) -y/(1+t);
0005 t0 = 0;
0006 y0 = 1;
0007 h = 0.1;
0008 T = 1;
0009 b = [1/6; 1/3; 1/3; 1/6];
0010 c = [0; 1/2; 1/2; 1];
0011 A = [0 0 0 0;
0012     1/2 0 0 0;
0013     0 1/2 0 0;
0014     0 0 1 0];
0015 analytic = @(t) 1./(1+t);
0016 [ y,t,err ] = explicit_RK( f,t0,y0,h,T,b,c,A,analytic );
0017 figure;
0018 plot(t,y,'o');           
0019 xlabel('t');
0020 ylabel('y(t)');
0021 hold on;
0022 ezplot(analytic, [0 1]);
0023 legend('numerical','analytic');
0024 f = @(t,y) 2*y/(1+t);
0025 analytic = @(t) (1+t).^2;
0026 [ y,t,err ] = explicit_RK( f,t0,y0,h,T,b,c,A,analytic );
0027 figure;
0028 plot(t,y,'o');           
0029 xlabel('t');
0030 ylabel('y(t)');
0031 hold on;
0032 ezplot(analytic, [0 1]);
0033 legend('numerical','analytic');
0034 
0035

Generated on Mon 18-Jan-2016 10:25:49 by m2html © 2005