Filter löschen
Filter löschen

Euler method Subroutine, Euler portion provided

1 Ansicht (letzte 30 Tage)
N/A
N/A am 19 Apr. 2020
Beantwortet: Ameer Hamza am 19 Apr. 2020
I have been provided the code below to solve an ODE using Euler's Method. I am unsure how to write the subroutine to implement this code to find a solution.
CODE:
function [X,Y]= euler(f,x_o,x_f,y_o,N)
if N<2
N=2;
end
h=(x_f-x_o)/N;
X=zeros(N+1,1);
M=max(size(y_o));
Y=zeros(N+1,M);
x=x_o; X(1)=x; y=y_o; Y(1,:)=y';
for i=1:N
k1=h*feval(f,x,y);
y=y+k1;
x=x+h;
X(i+1)=x;
Y(i+1,:)=y';
end
end

Akzeptierte Antwort

Ameer Hamza
Ameer Hamza am 19 Apr. 2020
Download the zip file given in this answer: https://www.mathworks.com/matlabcentral/answers/98293-is-there-a-fixed-step-ordinary-differential-equation-ode-solver-in-matlab-8-0-r2012b#answer_107643 and study the code of ode1.m. It is the implementation of the Euler method provided in very early releases of MATLAB. It is no longer included in MATLAB, but it is still useful to understand the implementation of the Euler method.

Weitere Antworten (0)

Kategorien

Mehr zu Mathematics finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by