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 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Luke Brunot
le 29 Oct 2018
Modifié(e) : Walter Roberson
le 29 Oct 2018
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,:);
0 commentaires
Réponse acceptée
madhan ravi
le 29 Oct 2018
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 commentaire
madhan ravi
le 29 Oct 2018
Modifié(e) : madhan ravi
le 29 Oct 2018
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.
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Startup and Shutdown dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!