Usage example for explicit_RK employing the original Runge-Kutta method
0001 % Usage example for explicit_RK 0002 % employing the original Runge-Kutta method 0003 0004 f = @(t,y) -10^2*(y - t^(-1)) - t^(-2); 0005 t0 = 1; 0006 y0 = 1; 0007 h = 0.029; 0008 % no increase in error if h =0.028 0009 T = 2; 0010 b = [1/6; 1/3; 1/3; 1/6]; 0011 c = [0; 1/2; 1/2; 1]; 0012 A = [0 0 0 0; 0013 1/2 0 0 0; 0014 0 1/2 0 0; 0015 0 0 1 0]; 0016 analytic = @(t) t.^(-1); 0017 [ y,t,err ] = explicit_RK( f,t0,y0,h,T,b,c,A,analytic ); 0018 figure; 0019 plot(t,y,'o'); 0020 xlabel('t'); 0021 ylabel('y(t)'); 0022 hold on; 0023 ezplot(analytic, [1 2]); 0024 legend('numerical','analytic');