Use of @ in a statement
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
EFREN
am 6 Feb. 2014
Bearbeitet: Walter Roberson
am 6 Feb. 2014
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;
0 Kommentare
Akzeptierte Antwort
Alan Weiss
am 6 Feb. 2014
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
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Problem-Based Optimization Setup finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!