DDE23 Function Error saying "The function has to be at the end. All the arguments after 'sol' have to be moved before the function"

조회 수: 1 (최근 30일)
Hello,
I keep getting the error message that "The function has to be at the end. All the arguments after 'sol' have to be moved before the function" when I am using the DDE23 function
Below is my code. Could anyone please tell me what I am doing wrong?
Thank you!
clear all
data=[0,1;
13 5685;
15 25796;
18 110811;
20 277178;
22 384506;
25 180901;
27 193199;
29 1242700;
32 1470600;
34 752500;
36 121045];
%time data
xdata = data(:,1);
%virus data
ydata = data(:,2);
%parameter guesses
param0 = [1000; 23; .1; 1e-6;];
%optimization algorithm
options = optimset('MaxFunEvals',2000);
param = fminsearch(@hiv_ssq, param0,[options]);
%solving the ode for the best fit
[t,yfit] = ode15s(@hiv_ode, xdata, [1e6;0;1], []);
%plotting V versus data
semilogy(xdata, ydata, 'ro', t, yfit(:,3), 'b');
lags = [1]; % this is where we specify the vector of taus
% we need a history function that is a column vector giving the value of y1
% and y2 in the past. Here we make these constant values.
function x = history(t)
x = [s/d; 0; 1];
end
% we define the function for the delay. the Y variable is the same as you
% should be used to from an ordinary differential equation. Z is the values
% of all the delayed variables.
function dYdt = ddefun(t,x,Z)
% additional variable
y1 = x(1);
y2 = x(2);
y3 = x(3);
% Z(:,1) = [y1(t - tau_1); y2(t - tau_2)]
y3_tau1 = Z(3,1);
dx(1) = (1e4)-.01*x(1)-b*x(1)*x(3);
dx(2) = b*x(1)*x(3)-d2*x(2);
dx(3) = N*d2*y_3tau1-c*x(3);
dYdt = [dx(1); dx(2); dx(3)];
end
sol = dde23(@ddefun;lags;@history;tspan)
y1 = sol.x(1,:); % note the y-solution is a row-wise matrix.
y2 = sol.x(2,:);
y3 = sol.x(3,:);

채택된 답변

madhan ravi
madhan ravi 2018년 10월 29일
function dYdt = ddefun(t,x,Z) % additional variable y1 = x(1); y2 = x(2); y3 = x(3);
% Z(:,1) = [y1(t - tau_1); y2(t - tau_2)]
y3_tau1 = Z(3,1);
dx(1) = (1e4)-.01*x(1)-b*x(1)*x(3);
dx(2) = b*x(1)*x(3)-d2*x(2);
dx(3) = N*d2*y_3tau1-c*x(3);
dYdt = [dx(1); dx(2); dx(3)];
end
  댓글 수: 1
madhan ravi
madhan ravi 2018년 10월 29일
편집: madhan ravi 2018년 10월 29일
The above should be at the very end as the error message states because when you define a function in a script file it has to be at the very end.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Numerical Integration and Differential Equations에 대해 자세히 알아보기

태그

제품


릴리스

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by