필터 지우기
필터 지우기

Using fminunc()

조회 수: 3 (최근 30일)
Kim O
Kim O 2012년 5월 20일
Hello,
I want to use x = fminunc(fun,x0);
For a litle test I choosed following structure:
fun=[x1+x2 ; sin(x3)];
fun==> 2x1 sym
x0 ==> 3x1 double
ERROR:
Error using optimfcnchk (line 288) If FUN is a MATLAB object, it must have an feval method.
Error in fminunc (line 239) funfcn = optimfcnchk(FUN,'fminunc',length(varargin),funValCheck,gradflag,hessflag); Thanks!
Btw: I know, x0 is near the solution BUT I don't know if the solution is a Minimum or Maximum ;(

채택된 답변

Sargondjani
Sargondjani 2012년 5월 20일
what do you want? what is the function you want to optimize for? fminunc searches for a minimum, but for instance x1+x2 is unbounded below (solution: x1=-inf, x2=-inf) and for sin(x3) has infinitely many minima...
anyway the format for fminunc (and fmincon) is the following:
myfunction=@(x)x(1)+x(2)+sin(x3);
x0=[1, 4, 10];
[x,y]=fminunc(myfunction,x0);
note that the my example does not have a solution...
  댓글 수: 1
Sargondjani
Sargondjani 2012년 5월 20일
o and the function your are trying to optimize should return 1 value as output (not 2 as you tried)

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

추가 답변 (3개)

Kim O
Kim O 2012년 5월 20일
Thank you! This funtion was just an example not really my problem. I have a n dimensional algebraic equation f(x,t)=0 with x0 and t0 near a MINIMUM or MAXIMUM. I guess for my Problem fminunc is the wrong method.
Btw:
myfunction=@(x)x(1)+x(2)+sin(x3); Is not working because my function f is 20 dimensional, I can't write it down, this should go automatically, but I don't know how.

Sargondjani
Sargondjani 2012년 5월 20일
what do you mean, you can't write it down?
you can create a function file if the function is hard to capture in one line: format is:
function [y]=my_function(x1,x2,...........)
y=.....%put calculations here
end
and store that as a .m-file, where matlab can call it (current directory for instance)
you can then call it with an anonymous function (this way you can also pass parameters):
ano_fun=@(x)my_function(x(1),x(2),....)
fminunc(ano_fun,x0);
if you want to find a local minimum or maximum you can do this with fminunc, you would just have to change the sign, of course (it would be helpful if you new before hand if it is min or max, hehe).

Walter Roberson
Walter Roberson 2012년 5월 21일
fminunc() cannot be applied to symbolic expressions (that is, expressions created by the Symbolic Toolbox.)
You can convert a symbolic expression to a function handle by using matlabFunction()

카테고리

Help CenterFile Exchange에서 Calculus에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by