matlabodedifferential-equationsdde

Solving DDE in Matrix form using Matlab


I need to solve following delayed equation:

Xdot = A*x(t) + B*U(t) + E(t)
U(t) = K*S*x(t-0.02) or U(t) = K*S*x(t-0.02)/alpha

in which:

A: 6*6 matrix 
K and alpha are scalar
S: 1*6 vector
E and U and x and B: 6*1 vectors.

I am using following code for solving the equation:

for i = 2:2688 
if  %(first condition ok)
    sol = dde23(@Insectorforce,0.02,history(:,i-1),[time(i-1) time(i)]);
else
    sol = dde23(@Outsectorforce,0.02,history(:,i-1),[time(i-1) time(i)]);                                                                                                          
end
x(:,i)=sol.x
history(i+2) = x(:,i); 
end

with following function files:

function xdot = Insectorforce(t,y,z,A,B,S,E,K,Beta,P)
  xdot = (A*y) - ((B*K*S/alpha)*(z)) + E;
end

and

function xdot = Outsectorforce(t,y,z,A,B,S,E,K)
  xdot = (A*y) - ((B*K*S*z) + E;
end

However, I get following error:

Error using Outsectorforce (line 2)
Not enough input arguments.

Error in dde23 (line 217)
f0 = feval(ddefun,t0,y0,Z0,varargin{:});

Error in filename (line 101)
sol = dde23(@Outsectorforce,0.02,history(:,i-1),[time(i-1) time(i)]);

What is wrong with my code? I don’t have problem with dimensions and I solved this equation without delay with ode23. However, I cannot manage to solve it using dde23 or ddesd.


Solution

  • dde23 requires function handles with three arguments. Try

    sol = dde23(@(t,y,z)(Insectorforce(t,y,z,A,B,S,E,K,Beta,P)),0.02,history(:,i-1),[time(i-1) time(i)]);
    

    and

    sol = dde23((@(t,y,z)(Outsectorforce(t,y,z,A,B,S,E,K)),0.02,history(:,i-1),[time(i-1) time(i)]);
    

    respectively.