Use of @ in a statement

1 次查看(过去 30 天)
A couple of years ago, a friend shared an optimization code obtained in this forum. Such code is shown below but i don't know for what I need to use the @ in the following statement: F = @(x) COST(x,tout,Vobs). Can you help me please?
Thanks a lot in advance...
x0 = [0.5 .5 .5]; % Just some Initial Condition
ub = [1 1 1]; % Upper bounds
lb = [0 0 0]; % Lower bounds
F = @(x) COST(x,tout,Vobs);
parameters_calc = fmincon(F,x0,[],[],[],[],lb,ub); %<-- FMINCON is the optimizer
legend({'Experimental Data','Fitted Data'});
% assign the estimated parameters to output variables
alfa_calc=parameters_calc(1);
beta_calc=parameters_calc(2);
lambda_calc=parameters_calc(3);
% Lets calculate the means squared error for future comparisons between
% models
V0=0;
[tout,Vcalc] = ode45(@dVdt,tout,V0,[],alfa_calc,beta_calc,lambda_calc);
MSE=sum((Vcalc-Vobs).^2)./length(Vcalc);
function COST = COST(x,t,Vobs)
A = x(1); %alfa
B = x(2); %beta
L = x(3); %lambda
V0=0;
% Given Vobs (i.e. experimental data), lets find the best parameters for the model:
% The cost function calls the ODE solver.
[tout,Vout] = ode45(@dVdt,t,V0,[],A,B,L);
COST = sum((Vout - Vobs).^2);
h = findobj('tag','solution');
set(h,'ydata',Vout);
title(['alfa = ' num2str(A) ' ' 'beta = ' num2str(B) ' lambda = ' num2str(L)]);
drawnow;

采纳的回答

Alan Weiss
Alan Weiss 2014-2-6
I am not sure that I understand your question. Perhaps this section of the documentation will enable you to figure it out for yourself.
Alan Weiss
MATLAB mathematical toolbox documentation

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Problem-Based Optimization Setup 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by