How to solve two differential equations using ode45

69 次查看(过去 30 天)
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