Asked by Michalis
on 19 Jan 2013

function [X,Y] = euler1(x,xf,y,n) h = (xf - x)/n; % step size X = x; % initial x Y = y; % initial y

for i = 1 : n % begin loop y = y + h*f(x,y); % Euler iteration x = x + h; % new x X = [X;x]; % update x-column Y = [Y;y]; % update y-column end % end loop

This is what i 've done but i don't know if it's correct. I would appreciate it if you tell me if everything is ok.

*No products are associated with this question.*

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi test

Learn moreOpportunities for recent engineering grads.

Apply Today
## 1 Comment

## Cedric Wannaz (view profile)

Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/59282#comment_123669

You could test it on a particular case from which you know the answer. This could be done step by step (using the debugger), or you could have the function print values (h,x,y, the latter two from the loop) and check them by hand using a small number of steps.