code of euler's method
Show older comments
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
on 22 May 2014
What's the expected result? What are the functions you're trying to solve?
Accepted Answer
More Answers (3)
SkyRazor
on 23 May 2014
0 votes
hello, could you please post your equation and give us some explanations?
ahmed abdelmageed
on 4 May 2020
0 votes
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
Sandip Das
on 28 Jul 2021
0 votes
%Published in 19th july 2021
%Sandip Das
clc
clear all
dydt=input('\n Enter the function : ');
x0=input('\n Enter initial value of x : ');
y0=input('\n Enter initial value of y : ');
xn=input('\n Enter the final value of x: ');
h=input('\n Enter the step length h: ');
i=0;
while i<xn
tempy=y0+h*dydt(x0,y0);
tempx=x0+h;
x0=tempx;
y0=tempy;
i=i+h;
end
fprintf('The value of y at t=%f is %f \n',x0,y0);
Categories
Find more on Logical in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!