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

22 views (last 30 days)
Devon Foster on 12 Apr 2021 at 19:51
Answered: James Tursa on 12 Apr 2021 at 20:17
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.

Alan Stevens on 12 Apr 2021 at 20:12
By substituting the first into the second and then the second into the third you can write the last two as:

James Tursa on 12 Apr 2021 at 20:17
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
E.g.,
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];
end
Use this function with ode45( ). Note that you are dividing by z and t, so you can't initialize either of those to 0.