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!