使用dde23时出错(第224行)导数和历史向量具有不同的长度

时间:2016-04-28 03:05:33

标签: dde

我正在尝试使用dde23求解一对延迟微分方程组。在运行以下代码时,我遇到了一个恼人的错误"衍生和历史向量有不同的长度"

function sol = prob1
    clf
   global Lembda alpha u1 u2  p q c d k a T  b zeta1 zeta2 A1 A2
   Lembda=2; b=0.07; d=0.0123; a=0.6; k=50; q=13; c=40; p=30; alpha = 0.4476; T=1; B=0.4; A1 =200; A2=100; zeta1=10; zeta2=30;
lags = [ 10; 0.2; 2; 10; 0.2;  10; 0.2; 2; 10; 0.2;  15; 0.9; 0.17; 0.01; 0.5; 0.000010; 0.00002];

sol = dde23(@prob2f,T,lags,[0,10], u1, u2);

function yp = prob2f(t,y,Z,B)
global Lembda alpha p b d c q T a k zeta1 zeta2 A1 A2
x2 = y(1);
y2 = y(2);
z2 =  y(3);
v = y(4);
w =  y(5);
xlag = Z(1,1);
vlag = Z(2,1);

%%%%%%%%%%%%%%%%
x1 = y(6);
y1 = y(7);
z1 = y(8);
v1 = y(9);
w1 = y(10);

x1lag = Z(1,1);
v1lag = Z(2,1);
%%%%%%%%%%%%%%%%%%%
lambda1 = y(11);
lambda2 = y(12);
lambda3 = y(13);
lambda4 = y(14);
lambda5 = y(15);
u1 =  y(16);
u2=   y(17);
lambda1lag = Z(1,1);
lambda4lag = Z(2,1);
%%%%%%%%%
dxdt=Lembda-d*x2-B*x2*v;
dydt=B*exp(-a*T)*xlag*vlag-a*y2 - alpha*y2*w;
dzdt=alpha*y2*w - b*z2;
dvdt=k*y2-p*v;
dwdt=c*z2-q*w;
%%%%%%%%% 
dx1dt=Lembda-d*x1-(1-u1)*B*x1*v1;
dy1dt=(1-u1)*B*exp(-a*T)*x1lag*v1lag-a*y1 - alpha*y1*w1;
dz1dt=alpha*y1*w1 - b*z1;
dv1dt=(1-u2)*k*y1-p*v1;
dw1dt=c*z1-q*w1;
%%%%%%%%%% 
dlambda1dt= A1+lambda1*d+(1-u1)*lambda1*B*v1-(1-u1)*lambda2*B*v1lag*exp(-a*T)*lambda2*(T);
dlambda2dt= a*lambda2+(lambda2-lambda3)*alpha*w1-lambda4*k*(u2-1);
dlambda3dt= b*lambda3-c*lambda5;
dlambda4dt= A2+(1-u1)*lambda1*B*x1+lambda4*p+lambda4*(T)*lambda2*x1lag*(u2-1)*exp(-a*T);
dlambda5dt=alpha*lambda2*z1-alpha*lambda3*z1+lambda5*q;
     du1dt = ( lambda2*x1lag*v1lag - lambda1*x1*v1)*(B/zeta1); 
     du2dt =(lambda4*k*y2)/zeta2;
yp = [ dxdt; dydt; dzdt; dvdt;dwdt; dx1dt; dy1dt; dz1dt; dv1dt;dw1dt; dlambda1dt; dlambda2dt; dlambda3dt ;dlambda4dt ;dlambda5dt; du1dt; du2dt ];

任何人都可以指导我,以便能够解决这个问题吗? 感谢

1 个答案:

答案 0 :(得分:3)

发生错误是因为您的返回向量yplags向量的大小不同。

lags向量的长度为17,但yp向量的长度为10.即使yp中有17个条目,其中很多都为{{1} }}

[]

你的prob2f()返回的长度和滞后的长度相同。这就是错误出现的原因

yp = [ dxdt; dydt; dzdt; dvdt;dwdt; dx1dt; dy1dt; dz1dt; dv1dt;dw1dt; 
dlambda1dt; dlambda2dt; dlambda3dt ;dlambda4dt ;dlambda5dt; du1dt; du2dt ];

K>> dxdt

dxdt =    
     []

K>> length(yp)    
    10

lags = [ 10; 0.2; 2; 10; 0.2;  10; 0.2; 2; 10; 0.2;  15; 0.9; 0.17; 0.01; 
       0.5; 0.000010; 0.00002];    
sol = dde23(@prob2f,T,lags,[0,10], u1, u2);

K>> length(lags)
    17

您需要检查f0 = feval(ddefun,t0,y0,Z0,varargin{:}); nfevals = nfevals + 1; [m,n] = size(f0); if n > 1 error(message('MATLAB:dde23:DDEOutputNotCol')) elseif m ~= neq error(message('MATLAB:dde23:DDELengthMismatchHistory')); <======== end 功能并确保prob2f的长度与延迟相同。