Filter löschen
Filter löschen

dde23: Derivative and history vectors have different lengths.

2 Ansichten (letzte 30 Tage)
Sylvia
Sylvia am 14 Mai 2015
Kommentiert: Sylvia am 15 Mai 2015
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];

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 14 Mai 2015
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.
  3 Kommentare
Walter Roberson
Walter Roberson am 14 Mai 2015
No, you created dnidt as a row vector. When you have a scalar and you extend it by assigning to the second element using
A(2) = VALUE
then the result is a row vector.
You can assign
dnidt = zeros(3,1);
or you can assign to
dnidt(2,1) = value;
or you can use
dnidt = dnidt.'
at the end.
Sylvia
Sylvia am 15 Mai 2015
Thanks, Walter. I just transposed dnidt.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Programming finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by