필터 지우기
필터 지우기

dde23: Derivative and history vectors have different lengths.

조회 수: 2 (최근 30일)
Sylvia
Sylvia 2015년 5월 14일
댓글: Sylvia 2015년 5월 15일
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];

채택된 답변

Walter Roberson
Walter Roberson 2015년 5월 14일
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
Walter Roberson
Walter Roberson 2015년 5월 14일
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 2015년 5월 15일
Thanks, Walter. I just transposed dnidt.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Programming에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by