Home > K25104 > ODEs > trapezoidal_rule_script_2.m

trapezoidal_rule_script_2

PURPOSE ^

Usage example for trapezoidal_rule

SYNOPSIS ^

This is a script file.

DESCRIPTION ^

 Usage example for trapezoidal_rule
 related to question 6.7

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 % Usage example for trapezoidal_rule
0002 % related to question 6.7
0003 
0004 f = @(t,y) -10^6*(y - t^(-1)) - t^(-2);
0005 t0 = 1;
0006 y0 = 1;
0007 h = 0.1;
0008 T = 2;
0009 analytic = @(t) t.^(-1);
0010 [ y,t,err ] = trapezoidal_rule( f,t0,y0,h,T,analytic );
0011 figure;
0012 plot(t,y,'o');           
0013 xlabel('t');
0014 ylabel('y(t)');
0015 hold on;
0016 ezplot(analytic, [1 2]);
0017 legend('numerical','analytic');

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