Modified Euler's method expansion

1 view (last 30 days)
PJS KUMAR
PJS KUMAR on 27 Sep 2018
suggest me to modify the following Euler's method expansion code so as to avoid the calculation of k2 two times
function []=EulerM(fn,a,b,y0,h)
x1=a;
y1=y0;
while(b>x1)
k1=y1+h*feval(fn,x1,y1);
k2=y1+h*(feval(fn,x1,y1)+feval(fn,x1+h,k1))/2;
while(abs(k1-k2)>0.0001)
k1=k2;
k2=y1+h*(feval(fn,x1,y1)+feval(fn,x1+h,k1))/2;
end
x1=x1+h;
y1=k2;
fprintf('when x=%5.2f y=%5.4f\n',x1,y1)
end

Answers (0)

Categories

Find more on Numerical Integration and Differential Equations in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!