Clear Filters
Clear Filters

How do I solve a system of (delayed) differential equations including known functions of the independant variable.

1 view (last 30 days)
I am trying to solve a set of 12 ODEs, where 4 of them have a 'delayed' term. I am using dde23 to solve them but I am just getting the same errors.
Here is my code:
k=[40,60,1/60,40,60,1/60,0.0004,0.0004,1000,1,1,0.1,0.0001,5];
y0 = [0,0,0,0,0,0,0,0,0.1,0.15,1,3.5];
time = 0:0.1:20;
sol = dde23(@PL_MRI_Kinetics_ODE,5*sqrt(2*k(13)),y0',time,k');
function ydot = PL_MRI_Kinetics_ODE(t,y,Z,k)
ydot = zeros(12,1);
ydot(1) = Inj(t)- (1/k(1))*y(1)+ k(9)*y(2)-k(10)*y(1)+Theta_z(t,k)*y(1);
%Pez
ydot(2) = - (1/k(2))*y(2)+ k(7)*y(4)-k(8)*y(2)+k(10)*y(1)-k(9)*y(2)+Theta_z(t,k)*y(2);
%Piz
ydot(3) = - (1/k(4))*y(3)+ k(11)*y(4)-k(12)*y(3)+Theta_z(t,k)*y(1);
%Lez
ydot(4) = - (1/k(5))*y(4)+ k(8)*y(2)-k(7)*y(4)+k(12)*y(3)-k(11)*y(4)+Theta_z(t,k)*y(4);
%Liz
ydot(5) = -(1/k(3))*y(5)+ k(9)*y(6)-k(10)*y(5)+Theta_xy(t,k)*Z(1);
%Pexy
ydot(6) = -(1/k(3))*y(6)+ k(9)*y(8)-k(9)*y(6)+k(10)*y(5)-k(9)*y(6)+Theta_xy(t,k)*Z(2);
%Pixy
ydot(7) = -(1/k(6))*y(7)+k(11)*y(8) -k(12)*y(7)+Theta_xy(t,k)*Z(3);
%Lexy
ydot(8) = -(1/k(6))*y(8)+k(8)*y(6)-k(7)*y(8)+k(12)*y(7)-k(11)*y(8)+Theta_xy(t,k)*Z(4);
%Lixy
ydot(9) = Inj(t)+ (1/k(1))*y(1)+(1/k(3))*y(5)+k(9)*y(10)-k(10)*y(9);
%Pet
ydot(10)= (1/k(2))*y(2)+(1/k(3))*y(6)+k(7)*y(12)-k(8)*y(10)+k(10)*y(9)-k(9)*y(10);
%Pit
ydot(11)= (1/k(4))*y(3)+(1/k(6))*y(7)+k(11)*y(12)-k(12)*k(11);
%Let
ydot(12)= (1/k(5))*y(4)+(1/k(6))*y(8)+k(8)*y(10)-k(7)*y(12)+k(12)*y(11)-k(11)*y(12);
%Lit
end
function Th_xy= Theta_xy(t,k)
Th_xy = exp(-(t).^2/(4*k(13)))/(2*(pi*k(13))^0.5)*(sind(k(14)));
for i=1:10
Th_xy = Th_xy +exp(-(t-i).^2/(4*k(13)))/(2*(pi*k(13))^0.5)*(sind(k(14)));
end
end
function Th_z = Theta_z(t,k)
Th_z = exp(-(t).^2/(4*k(13)))/(2*(pi*k(13))^0.5)*(cosd(k(14))-1);
for i=1:10
Th_z = Th_z +exp(-(t-i).^2/(4*k(13)))/(2*(pi*k(13))^0.5)*(cosd(k(14))-1);
end
end
function Inj_fun= Inj(t)
Inj_fun = zeros(length(t),1);
for i=1:length(t)
if (t(i)>=0)&&(t(i)<=10)
Inj_fun(i) = 1;
else
Inj_fun(i) = 0;
end
end
end
All I get out is a series of error messages.
Not enough input arguments.
Error in PL_MRI_Kinetics_ODE
ydot(1) = Inj(t)- (1/k(1))*y(1)+ k(9)*y(2)-k(10)*y(1)+Theta_z(t,k)*y(1);
Error in dde23
f0 = feval(ddefun,t0,y0,Z0,varargin{:});
Error in solver
sol = dde23(@PL_MRI_Kinetics_ODE,5*sqrt(2*k(13)),y0',time,k');
I have a feeling the problem lies in the functions Inj(t), Theta_xy(t) and Theta_z(t) which spit arrays of numbers, rather than being just a single number. I am not sure how to deal with this.
  1 Comment
Torsten
Torsten on 16 Aug 2018
Both the call to dde23 and the list of input parameters for "PL_MRI_Kinetics_ODE" are incorrect.
Look up the documentation for dde23.
Best wishes
Torsten.

Sign in to comment.

Answers (0)

Categories

Find more on Programming 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!