Here's a MATLAB function that implements Euler's method to solve an initial value problem (IVP) for a first order ordinary differential equation (ODE):
main.m643 chars24 linesYou can use this function by passing in the function f defining the ODE, the initial condition y0, the initial time t0, the final time tf, and the step size h. For example, let's use Euler's method to solve the IVP y' = -y, y(0) = 1 from t = 0 to t = 5 with step size h = 0.1:
main.m302 chars13 lines
This will produce a plot of the solution:

gistlibby LogSnag