Euler's Method
Euler's Method assumes our solution is written in the form
of a Taylor's Series. That is, we'll have a function of the
form:
For Euler's Method, we just take the first 2 terms only.
or simply
Continue..
Continue…
Euler Method on MATLAB
f=@(x,y)(x/y)
a=0;
b=2;
ya=1;
n=10;
h=(b-a)/n; % h is the step
y=zeros(+1,1); % memory allocation, zero column vector
y(1)=ya;
for j=1:n
y(j+1)=y(j)+h*f(x(j),y(j)); % Euler's formula
x(i+1)=x(i)+h;
end
plot(x,y,'-b')
hold on
syms y(x)
ode= diff(y,x)== x/y ;
cond=y(0)==1;
S=dsolve(ode,cond)
F=matlabFunction(S)
fplot(F,[0,2],'r',"LineWidth",2);
hold off