필터 지우기
필터 지우기

Example code for fmincon error.

조회 수: 1 (최근 30일)
xinyu
xinyu 2013년 2월 23일
Hello, everyone. I was tryint to get the idea of using the function fmincon earlier. But when I run the example code in the hlep document, it seems that it doesn't work. the code:
function f = myfun(x)
f = -x(1) * x(2) * x(3);
= [-1 -2 -2; ...
1 2 2];
b = [0;72];
x0 = [10;10;10]; % Starting guess at the solution
[x,fval] = fmincon(@myfun,x0,A,b);
According to the hlep, a solution to the optimize problem should be given. But when I copied the code into a new script and run it, I got the error:
>> myfun
Error using myfun (line 2)
Not enough input arguments.
what does this means here, can anybody please explain this to me?

채택된 답변

Shashank Prasanna
Shashank Prasanna 2013년 2월 23일
is you objective function, you shouldn't run that. Create the definition of myfun into a separate file called myfun.m:
function f = myfun(x)
f = -x(1) * x(2) * x(3);
= [-1 -2 -2; ...
1 2 2];
And the rest of the code into a different script for example run_fmincon.m:
b = [0;72];
x0 = [10;10;10]; % Starting guess at the solution
[x,fval] = fmincon(@myfun,x0,A,b);
>> run_fmincon
  댓글 수: 1
xinyu
xinyu 2013년 2월 23일
That's correct. Thank you very much.

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

추가 답변 (0개)

카테고리

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