How to solve two differential equations using ode45

조회 수: 44 (최근 30일)
Rahula Hoop
Rahula Hoop 2019년 8월 8일
답변: Shubham Gupta 2019년 8월 21일
My system of equations is as follows:
I need to solve these differential equations using ode45.
At t=0 the parameters have the following values: p1 = p2 = 0.25, c1 = c2 = 1, e1 = e2 = 0.7, over the interval [0,20].
The question goes on to ask which single parmeter should be changed to obtain an asymptotically stable steady state.
I am confused regarding the implementation of e and c in the formula as all other examples only have 2 variables, not 4... Help would be greatly appreciated.
Please see my Matlab script below:
clear
clc
f = @(t,y,c,e) [y(1); c(1)*y(1)*(1-y(1)) - e(1)*y(1); y(2); c(2)*y(2)*(1-y(1)-y(2)) - e(2)*y(2) - c(1)*y(1)*y(2)];
y0 = 0.25;
c(1) = 1;
c(2) = 1;
e(1) = 0.7;
e(2) = 0.7;
tspan = [0,20];
Y0 = [0.25;0.0125;0.25;-0.1125];
[T,Y,C,E] = ode45(f,tspan,Y0)
  댓글 수: 2
Shubham Gupta
Shubham Gupta 2019년 8월 8일
Are you sure, e1,e2,c1,c2 are time-variant and not constant ? If they are time-variant then there should be differential terms of those terms too. Since, there are only two differenctial eqaution and 6 unknown these differential equations become unsolvable by conventional methods.
If e1,e2,c1,c2 are constant then we will have 2 equation and 2 unknown, which can easily be solved using ode using following model :
clear
clc
c1 = 1;
c2 = 1;
e1 = 0.7;
e2 = 0.7;
f = @(t,y) [c1*y(1)*(1-y(1)) - e1*y(1);c2*y(2)*(1-y(1)-y(2)) - e2*y(2) - c1*y(1)*y(2)];
tspan = [0,20];
Y0 = [0.25;0.25];
[T,Y] = ode45(f,tspan,Y0);
I hope it helps !
Rahula Hoop
Rahula Hoop 2019년 8월 17일
Hi Shubham, your answer was perfect, thank you so much for your help!
If you would like to post your comment as an answer I'll happily select it as the solution.
Thanks again for the help, I was close but I just didn't know what to alter to make it work.

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

채택된 답변

Shubham Gupta
Shubham Gupta 2019년 8월 21일
Are you sure, e1,e2,c1,c2 are time-variant and not constant ? If they are time-variant then there should be differential terms of those terms too. Since, there are only two differenctial eqaution and 6 unknown these differential equations become unsolvable by conventional methods.
If e1,e2,c1,c2 are constant then we will have 2 equation and 2 unknown, which can easily be solved using ode using following model :
clear
clc
c1 = 1;
c2 = 1;
e1 = 0.7;
e2 = 0.7;
f = @(t,y) [c1*y(1)*(1-y(1)) - e1*y(1);c2*y(2)*(1-y(1)-y(2)) - e2*y(2) - c1*y(1)*y(2)];
tspan = [0,20];
Y0 = [0.25;0.25];
[T,Y] = ode45(f,tspan,Y0);
I hope it helps !

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Ordinary Differential Equations에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by