Euler's Method system of odes

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);

답변 (1개)

Jan
Jan 2021년 4월 24일
편집: Jan 2021년 4월 24일

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;

댓글 수: 3

Karol T
Karol T 2021년 4월 24일
Right, my fault. But still the drawing is one straight f = 0
Karol T
Karol T 2021년 4월 24일
Drawing of (t,x)
If x starts at 0, it must sty at 0 according to the formula. y is not a straight line:
plot(t(1:100), y(1:100))

댓글을 달려면 로그인하십시오.

카테고리

질문:

2021년 4월 24일

댓글:

Jan
2021년 4월 25일

Community Treasure Hunt

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

Start Hunting!

Translated by