How do I solve a system of nonlinear differential equations like the one below?
1 view (last 30 days)
Show older comments
Andrian Mirza
on 18 Mar 2021
Commented: Star Strider
on 2 May 2021
As seen below (ode1 ode2 ode3) are my equations and c_1 to c_9 are just some constants which will be later determined. Is there any way to solve this without numerical methods? Thank you!
syms x(t) y(t) z(t);
c_1 = 1
c_2 = 2
c_3 = 1
c_4 = 1
c_5 = 1
c_6 = 1
c_7 = 1
c_8 = 1
c_9 = 1
ode1 = diff(x,t) == c_1*(c_3-x) + c_2*(x-y);
ode2 = diff(y,t) == c_4*(x-y) - c_5*c_6*y*(1-z) + c_7*c_6*exp(c_8 - c_9*z);
ode3 = diff(z,t) == c_5*y*(1-z) - exp(c_8 - c_9*z);
odes = [ode1; ode2; ode3]
cond1 = y(0) == 0;
cond2 = x(0) == 0;
cond3 = z(0) == 0;
conds = [cond1 cond2 cond3];
0 Comments
Accepted Answer
Star Strider
on 18 Mar 2021
Add t and Y to the syms declaration, and add these to the end of the posted code:
[VF,Subs] = odeToVectorField(odes);
odefcn = matlabFunction(VF, 'Vars',{t,Y});
Then use ‘odefcn’ with the numerical ODE integrator of your choise (such as ode45) to integrate them numerically.
Use the ‘Subs’ variable to determine the variable assignment order in the function and in the outputs of the integration.
2 Comments
Star Strider
on 2 May 2021
As always, my pleasure!
Try this —
syms x(t) y(t) z(t) t Y
c_1 = 1
c_2 = 2
c_3 = 1
c_4 = 1
c_5 = 1
c_6 = 1
c_7 = 1
c_8 = 1
c_9 = 1
ode1 = diff(x,t) == c_1*(c_3-x) + c_2*(x-y);
ode2 = diff(y,t) == c_4*(x-y) - c_5*c_6*y*(1-z) + c_7*c_6*exp(c_8 - c_9*z);
ode3 = diff(z,t) == c_5*y*(1-z) - exp(c_8 - c_9*z);
odes = [ode1; ode2; ode3]
[VF,Subs] = odeToVectorField(odes)
odefcn = matlabFunction(VF, 'Vars',{t,Y});
[t,y] = ode45(odefcn, [0 50], zeros(1,3)+1E-8);
figure
plot(t, y)
grid
legend(string(Subs), 'Location','best')
ylim([-1 1]*5)
.
More Answers (0)
See Also
Categories
Find more on Ordinary Differential Equations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!