MATLAB Answers


ODE45 wont run, just says "error"?

Asked by Nathan Corbissero on 16 Sep 2019
Latest activity Commented on by Star Strider
on 16 Sep 2019
Hi all, first post here so sorry If I am leaving out details. I am writing an ODE45 file which contains a nested rate function. I've done this numerous times before, but I am getting an error which does not specify where I should look to debug.
function res = renalclearance()
t_final = 120; %minutes
[T,M] = ode45(@renal_rate, [0,t_final], 10); %10 = initial concentration (mmol/L)
Y = M(:,1);
W = M(:,2);
figure(1) %dci/dt
figure(2) %dce/dt
function res = renal_rate(t,Z)
Ci = Z(1);
Ce = Z(2);
kc = 0.77; %L/min
kt = 0.25; %L/min
qf = 0.083; %L/min
gi = 0.1; %mmmol/min
v0 = 40; %L
vr = 1.67;
vt = v0-(t*qf);
vi = ((vt)/(1+(1/vr)));
ve = ((vt)/(1+vr));
vdi = 1/(1.598);
vde = 1/(2.67);
dci_dt = -((vdi+kc)*(Ci/vi))+((kc*Ce + gi)/(vi));
dce_dt = -((vde+kc+kt)*(Ce/ve))+((kc*Ci)/(ve));
res = [dci_dt,dce_dt];
And here is the corresponding error message:
Error in renalclearance (line 5)
[T,M] = ode45(@renal_rate, [0,t_final], 10); %10 = initial concentration (mmol/L)


Sign in to comment.



1 Answer

Answer by Star Strider
on 16 Sep 2019
 Accepted Answer

You have two problems:
First, your system has two differential equations, so you must have two initial conditions:
ic = [0 10];
[T,M] = ode45(@renal_rate, [0,t_final], ic); %10 = initial concentration (mmol/L)
Second, ‘renal_rate’ has to return a column vector:
res = [dci_dt; dce_dt];
Note the vertical concatenation operator here, (;). With these changes your code runs without error. Change the initial conditions (the ‘ic’ vector) if I guessed wrong as to what they should be.


That worked perfectly! Thank you so much.
Star Strider
on 16 Sep 2019
As always, my pleasure!

Sign in to comment.