Euler's Method system of odes
Ältere Kommentare anzeigen
Hello, I'm new to MATLAB and I'm stuck. I am trying to solve two first order ode using the Forward Eulers method. I thought my code was correct, but I think the first plots arewrong. Can someone please take a look at this?
%parametrs
A= 5;
B=50;
C=0.1;
D=1e-5;
h=0.0001;
t_final=10;
N=t_final/h;
t(1)=0;
x(1)=0;
y(1)=0;
% equations
% dx/dt = 1/D*x
% dy/dt=(1/C)*(A-(B*y)-x)
for i=1:N
t(i+1)=t(i)+h;
x(i+1)=(1./D)*x(i);
y(i+1)=(1./C)*(A-(B*y(i))-x(i));
end
figure(1);clf(1)
plot(t,x)
figure(2);clf(2)
plot(t,y);
Antworten (1)
You determine the derivatives:
% dx/dt = 1/D*x
% dy/dt=(1/C)*(A-(B*y)-x)
Now x(i+1) and y(i+1) are not the values of these derivatives at the point x(i), y(i), but:
x(i+1) = x(i) + (1./D)*x(i) * h;
y(i+1) = y(i) + (1./C)*(A-(B*y(i))-x(i)) * h;
Kategorien
Mehr zu Ordinary Differential Equations finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!