I am trying to solve a syste of delay differential equations, but the error: Derivative and history vectors have different lengths keeps occuring. I have taken notes from other similar questions and made sure that ylag and output of derivatives have the same length and made sure that my constants are not global. However, the error is not resolved.
For reference, this is my system:
Here is my code
lags=[2,2,2,2,2,2,2,2];
tspan=linspace(0,50);
sol=dde23(@deriv,lags,@history,tspan);
%-----------------------------------------
function dydt=deriv(~,y,z)
ylag1=z(:,1);
ylag2=z(:,2);
ylag3=z(:,3);
ylag4=z(:,4);
ylag5=z(:,5);
ylag6=z(:,6);
ylag7=z(:,7);
ylag8=z(:,8);
n1=30290000;
a1=0.98*n1;
m=0.00055;
eps=1/5;
b1=0.000024246;
chi=0.071;
B1=0.5;
eta=0.5;
k1=0.185;
phi1=0.26;
alpha1=0.1155;
delta=0.0225;
omega1=0.26;
dydt=[b1-((y(1)*B1*(y(3)+y(4)+(eta*y(6))))/a1)-b1*y(1)-m*ylag1;
((y(1)*B1*(y(3)+y(4)+(eta*y(6))))/a1)-(k1+eps)*y(2)-m*ylag2;
k1*eps*y(2)-(alpha1+chi)*y(3)-m*ylag3;
(1-k1)*eps*y(2)-(phi1+omega1)*y(4)-m*ylag4;
k1*y(2)+alpha1*y(3)-chi*y(5);
(phi1+omega1)*y(4)-(chi+delta)*y(6);
ch*(y(5)+y(6))-b1*y(7)-m*ylag7;
delta*y(5)];
end
%-------------------------------------
function s=history(~)
a1=0.98*30290000;
s=[(a1-13),0,5,7,0,1,0,0];
end
%-------------------------------------

 採用された回答

Alan Stevens
Alan Stevens 2021 年 2 月 9 日

0 投票

Change
ylag1=z(:,1);
ylag2=z(:,2);
ylag3=z(:,3);
ylag4=z(:,4);
ylag5=z(:,5);
ylag6=z(:,6);
ylag7=z(:,7);
ylag8=z(:,8);
to
ylag1=z(1);
ylag2=z(2);
ylag3=z(3);
ylag4=z(4);
ylag5=z(5);
ylag6=z(6);
ylag7=z(7);
ylag8=z(8);
and
ch*(y(5)+y(6))-b1*y(7)-m*ylag7;
to
chi*(y(5)+y(6))-b1*y(7)-m*ylag7;
and it works.

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeDynamic System Models についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by