Can I use two separate ODE call functions for a system of two differential equations in MatLab?

100 views Asked by At

I am trying to code a system of ODE's shown below.

First quation

Second equation

As seen, the second ODE completely depends on the value of the first ODE.
How can I code the second ode? I am using ode45.

1

There are 1 answers

5
am304 On BEST ANSWER

Yes, that's quite possible. Define x as [c;ce], then you have something like:

function dx = my_ode(t,x)

% parameters definition
kf = ...; % whatever value you are using
P0 = ...; % whatever value you are using
Jer = ...; % whatever value you are using
J_serca = ...; % whatever value you are using
gamma = ...; % whatever value you are using

% differential equations
dc = (kf*P0+Jer)*(x(2)-x(1)) - J_serca;
dce = -gamma*dc;
dx = [dc;dce];

and then you can call the ode solver as:

tspan = [0 10]; % or whatever time interval you want to solve the odes on
x_init = [0;0]; % ot whatever initial conditions you want to use
[T,Y] = ode45(@my_ode,tspan,x_init);