Modified Euler's method expansion

1 次查看(过去 30 天)
PJS KUMAR
PJS KUMAR 2018-9-27
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

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Mathematics 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by