Optimization via an Integral
조회 수: 1 (최근 30일)
이전 댓글 표시
Hey there, I would like to maximize a function W=5*si0-int(r0,0,si0*n0), where si0 and n0 are the decision variables and r0=(n0*si0)^2. Constraints are just nonnegativity of si0 and n0. Script copied from the editor:
function W=kiratest;
syms si0
syms n0
r0=(n0*si0).^2
W=-(5.*si0-int(r0,0,si0*n0));
I already tried fmincon and linprog, but I always get several errors, such as:
>> fmincon(@kiratest,[0 0],[-1 0;0 -1],[0;0])
Warning: Trust-region-reflective algorithm does not solve this type of problem,
using active-set algorithm. You could also try the interior-point or sqp
algorithms: set the Algorithm option to 'interior-point' or 'sqp' and rerun. For
more help, see Choosing the Algorithm in the documentation.
> In fmincon at 472
??? Error using ==> kiratest
Too many input arguments.
Error in ==> fmincon at 590
initVals.f = feval(funfcn{3},X,varargin{:});
Caused by:
Failure in initial user-supplied objective function evaluation. FMINCON cannot
continue.
AND:
>> linprog(@kiratest,[-1 0;0 -1],[0;0])
??? Error using ==> linprog at 132
LINPROG only accepts inputs of data type double.
Please help me find the mistake or else another solution for optimization. Sincerely, Kira
댓글 수: 0
채택된 답변
Matt J
2013년 10월 5일
편집: Matt J
2013년 10월 5일
The fmincon error is because you've defined no input arguments for kiratest(). If si0, n0 are the decision variables, then the vector [si0,n0] should be its input. Because of the missing input arguments, it's hard to know what your objective function is really meant to be, but I'm guessing it is
function W=kiratest(x);
si0=x(1);
n0=x(2);
W=-(5.*si0 - (si0*n0)^3/3); %did the integral by hand
end
Also, you should use fmincon's "lb" argument to express the positivity constraints
fmincon(@kiratest,[0 0],[],[],[],[],[0;0],[]).
As for LINPROG, the error is due to you passing it a function handle argument @kiratest, which is not the kind of input it accepts. In any case, your problem does not appeat to be a linear program, so linprog will not be applicable.
댓글 수: 2
Matt J
2013년 10월 6일
Please highlight your code and format it using the
toolbar button, so that it is more readable.
추가 답변 (0개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!