Numerical Computing with MATLAB

The simplest numerical method for the solution of initial value problems is Euler's method. It uses a fixed step size h and generates the approximate solution by
The MATLAB code would use an initial point t0, a final point tfinal, an initial value y0, a step size h, and an inline function or function handle f. The primary loop would simply be
t = t0; y = y0; while t <= tfinal y = y + h*feval(f,t,y) t = t + h end
Note that this works perfectly well if y0 is a vector and f returns a vector.
As a quadrature rule for integrating f(t), Euler's method corresponds to a rectangle rule where the integrand is evaluated only once, at the left-hand endpoint of the interval. It is exact if f(t) is constant, but not if f(t) is linear. So the error is proportional to h. Tiny steps are needed to get even a few digits of accuracy. But, from our point of view, the biggest defect of Euler's method is that it does not provide an error estimate. There is no automatic way to determine what step size is needed to achieve a specified accuracy.