Using the function fmincon

조회 수: 9 (최근 30일)
Auryn_
Auryn_ 2019년 9월 2일
댓글: Auryn_ 2019년 9월 2일
Hi,
I want to optimise a function that I called FUNCTION where
function [Err]=FUNCTION(coef)
data1=...
data2=...
[x1]=Function1(coef, data1, data2); %Function1 is an additional function
% % return the error
Err=1-x1;
end
I have this function FUNCTION and try to minimize Err using fmincon:
Aeq=[1 1 1 1 1 1 1 1 1 1;1 -1 1 -1 1 -1 1 -1 1 -1];
beq=[0;1];
[x] = fmincon (FUNCTION(coef),coef,[],[],Aeq,beq);
I don't know why is not working and gives me an error :
"Error using optimfcnchk (line 101)
FUN must be a function, a valid character vector
expression, or an inline function object.
Error in fmincon (line 409)
funfcn =optimfcnchk(FUN,'fmincon',length(varargin),funValCheck,flags.grad,flags.hess,false,Algorithm); "
I appreciate in advance any help you could provide me!

채택된 답변

Torsten
Torsten 2019년 9월 2일
[x] = fmincon (@FUNCTION,coef,[],[],Aeq,beq);
  댓글 수: 3
Walter Roberson
Walter Roberson 2019년 9월 2일
[x] = fmincon (@(coef)FUNCTION(coef),coef,[],[],Aeq,beq);
Auryn_
Auryn_ 2019년 9월 2일
Hi again,
could I specify to stop fmincon if the Err is less than a certain value?

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Adam
Adam 2019년 9월 2일
The first argument needs to be a function handle, not a call to the function, although your function is FUNCTION so I'm not sure what FUN is, but you certainly shouldn't be passing the argument to it.
@FUNCTION
would seem like what you should be passing in.
  댓글 수: 4
Torsten
Torsten 2019년 9월 2일
Use an output function.
An example to stop fmincon if a certain condition holds is given under
https://de.mathworks.com/help/optim/ug/output-functions.html
Auryn_
Auryn_ 2019년 9월 2일
Thanks!

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Solver Outputs and Iterative Display에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by