Error message when using optimization toolbox
2 次查看(过去 30 天)
显示 更早的评论
Hello all,
I am trying to fit a system of ODEs to epidemiological data and thus obtain values for the parameters. The function I created is defined as:
function Ebola
global beta gamma N k f R0;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% set the end time to run the simulation %
% set initial conditions as a column vector %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
tend = 351; % end time (151 days)
u0 = [10^6; 0; 425; 0; 425]; % initial conditions vector (425 cases)
N = 10^6; % population size (assume constant)
beta = 0.27; % transmission rate
gamma = 1/(5.61); % recovery rate (1 / avg. time in compartment)
k = 1/(5.3); % transfer rate from E --> I (1 / avg. time in compartment)
f = 0.75; % case fatality (slope of cases vs. deaths??)
R0 = beta/gamma;
[tsol, usol] = ode45(@rhs, [0, tend], u0);
Ssol = usol(:, 1);
Esol = usol(:, 2);
Isol = usol(:, 3);
Rsol = usol(:, 4);
Csol = usol(:, 5);
% sol = [tsol Isol];
%%%%%%%%%%%%%%%%%%
% Plots %
%%%%%%%%%%%%%%%%%%
figure
plot(tsol, Ssol, 'b-'); hold on;
plot(tsol, Esol, 'r--');
plot(tsol, Isol, 'r-');
plot(tsol, Rsol, 'g-');
plot(tsol, Csol, 'm-');
legend('susceptible', 'exposed', 'infected', 'recovered', 'cases' );
xlabel('time (days)');
ylabel('population density');
title('Susceptibles and Infected vs Time');
figure
plot(Ssol, Isol, 'r');
title('Susceptible vs Infected');
xlabel('susceptible');
ylabel('Infected');
% set(gca, 'XTick', 10:tend);
function udot = rhs(t, u)
global beta gamma N k f R0;
S=u(1);
E=u(2);
I=u(3);
R=u(4);
C=u(5);
%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Model %
%%%%%%%%%%%%%%%%%%%%%%%%%%%
Sdot = (-beta*S*I)/N;
Edot = (beta*S*I)/N - k*E;
Idot = k*E - gamma*I;
Rdot = (1-f)*gamma*I;
Cdot = k*E;
udot = [Sdot; Edot; Idot; Rdot; Cdot];
When I call "Ebola" in the optimization toolbox, I Received the following message:
Optimization running.
Error running optimization.
Too many output arguments.
Is the function too complex?
Could someone please tell me what I'm doing wrong? It is my first time using the toolbox and I haven't been able to solve it by reading the documentation. A million thanks.
0 个评论
回答(1 个)
Alan Weiss
2015-12-11
It is not clear to me how you are calling an optimization routine based on your Ebola function.
At the very least, an objective function must accept an argument, usually called x, and return a scalar value. The argument x represents a vector (or array) of parameters that the solver modifies in order to minimize the scalar returned value. I do not see Ebola accepting any arguments. Nor do I see it returning a scalar. All optimization objective functions should look like this:
function y = thefunction(x)
The returned y is the objective function value at the multidimensional point x.
Alan Weiss
MATLAB mathematical toolbox documentation
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Direct Search 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!