Optimization via an Integral

3 views (last 30 days)
Kira
Kira on 5 Oct 2013
Commented: Matt J on 6 Oct 2013
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

Accepted Answer

Matt J
Matt J on 5 Oct 2013
Edited: Matt J on 5 Oct 2013
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 Comments
Kira
Kira on 6 Oct 2013
Hey Matt, yes thank you, you are right about the input and lb of course. However, I guess the core problem is the integral (since I am able to make fmincon work without it). So now:
function W=kiratest(v); si0=v(1); n0=v(2); r0=(n0*si0).^2; W=-(5.*si0-int(r0,0,n0*si0));
GETS ME:
??? Undefined function or method 'int' for input arguments of type 'double'.
Error in ==> kiratest at 5 W=-(5.*si0-int(r0,0,n0*si0)); 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.
So I would really appreciate further help. Best regards, Kira
Matt J
Matt J on 6 Oct 2013
Please highlight your code and format it using the
toolbar button, so that it is more readable.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!