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;
댓글 수: 0
채택된 답변
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 Center 및 File Exchange에서 Problem-Based Optimization Setup에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!