MATLAB: Dde23: Derivative and history vectors have different lengths.

dde23

Hi, I'm trying to solve a very basic set of time-delay differential equations with dde23. All my code is below. collFunc2 is the driver, which sets three time lags — taui, taug, tauf — and calls dde23 on the set of three coupled differential equations — dnidt — in collFunc2. The history values are constant and zero in coll2hist. When I try to run this I get 'Derivative and history vectors have different lengths.' Both seem to be three columns long to me. What am I doing wrong? Thanks so much for any help. – Sylvia
function sol = collision2
taui = 15*60;
taug = 30*60; % graupel growth time
tauf = 10*60; % fallout time
lags = [taui, taui + taug, taui + taug + tauf];
sol = dde23(@collFunc2,lags,@coll2hist,[0,1000]);
function [t,dnidt] = collFunc2(t,y,Z)
alpha = 2.4*10^(-5); % volume sweep out rate [m3 s-1]
N = 50; % multiplication rate
ylag1 = Z(:,1); ylag2 = Z(:,2); ylag3 = Z(:,3);
dnidt(1) = alpha*N*((y(2)*y(3) - ylag1(2)*ylag1(3)));
dnidt(2) = alpha*N*(ylag1(2)*ylag1(3) - ylag2(2)*ylag2(3));
dnidt(3) = alpha*N*(ylag2(2)*ylag2(3) - ylag3(2)*ylag3(3));
function s = coll2hist(~)
% Constant history function
s = [0; 0; 0];

Best Answer

The output of the delay differential equation is expected to have a single output that is a column vector that is the derivatives. Instead you have two outputs, the first of which is a copy of the time. But the time is a scalar, and a scalar does not match the history vector size of being a 3x1 vector.