MATLAB Answers

code of euler's method

508 views (last 30 days)
Hi, i follow every protocol steps for euler's method, but my results are too increased and they are not correct. Anyone could see if i´m doing anything wrong? i think it happens because my derivatives are floating too much.

  1 Comment

Sara
Sara on 22 May 2014
What's the expected result? What are the functions you're trying to solve?

Sign in to comment.

Accepted Answer

George Papazafeiropoulos
George Papazafeiropoulos on 23 May 2014
A simple application of Euler method:
Define the function:
function E=euler(f,a,b,ya,M)
h=(b-a)/M;
Y=zeros(1,M+1);
T=a:h:b;
Y(1)=ya;
for j=1:M
Y(j+1)=Y(j)+h*f(T(j));
end
E=[T' Y'];
end
where - f is the function entered as function handle
- a and b are the left and right endpoints
- ya is the initial condition E(a)
- M is the number of steps
- E=[T' Y'] where T is the vector of abscissas and Y is the vector of ordinates
Then run the code:
f=@(x) x^2;
a=0;
b=10;
ya=0;
M=200;
YY=euler(f,a,b,ya,M)
You can adjust your problem according to the above algorithm.

  0 Comments

Sign in to comment.

More Answers (1)

SkyRazor
SkyRazor on 23 May 2014
hello, could you please post your equation and give us some explanations?

  0 Comments

Sign in to comment.

Sign in to answer this question.