Section 2.5: A Closer Look at the Euler Method 155
% ‘impeuler’, ‘rk’ (Runge-Kutta), ‘ode23’, ‘ode45’.
% Results are saved at the endPoints of n subintervals,
% that is, in steps of length h = (b – t0)/n. The
% result t is an (n+1)-column vector from b to t1,
% while y is a matrix with n+1 rows (one for each
% t-value) and one column for each dependent variable.
To use the improved Euler method, we call as ‘method’ the following function.
function [t,y] = impeuler(yp, t0,t1, y0)
%
% [t,y] = impeuler(yp, t0,t1, y0)
% Takes one improved Euler step for
%
% y’ = yprime( t,y ),
%
29. Here our differential equation is described by the MATLAB function
function vp = vpbolt1(t,v)
vp = -0.04*v – 9.8;
Then the commands