MATLAB Answers

How can I solve a system of ODE's, in which the equations have a dependency on time, as well as the other ODEs?

1 view (last 30 days)
Devon Foster
Devon Foster on 12 Apr 2021
Answered: James Tursa on 12 Apr 2021
I have a system of ODE's that depend on time, as well as the other ODE's. I have searched the forum something of this type and can't quite seem to find something similar. For example, how could I solve something of the form:
I have shortened the equations significantly as I am after the process of how to solve these ODEs (and the equations I am attempting to solve are much longer). I am familiar with ODE 45, but something about the system only being first order while the derivatives being contained in the other equation, and the independant variable appearing in the equations is throwing me off. Thank you very much for any help.

Answers (2)

James Tursa
James Tursa on 12 Apr 2021
Just code it up as it appears using a 3-element state vector, where the elements are defined as follows
y(1) = x
y(2) = y
y(3) = z
function dy = myderiv(t,y)
dxdt = y(1) * (t + y(2)) - y(1)^2;
dydt = dxdt / y(3) - y(2);
dzdt = y(3) * (dydt + y(2)/t);
dy = [dxdt;dydt;dzdt];
Use this function with ode45( ). Note that you are dividing by z and t, so you can't initialize either of those to 0.

Community Treasure Hunt

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

Start Hunting!

Translated by