f



Using fmincon with 3 parameters to optimize

hi everybody,

I would like to use fmincon to optimize a cost function by optimizing 3 parameters.

This is basicly the code I'm using:

initial_guess = [refR; refG; refB] 
J = @(rR, rG, rB) sum(abs(X_ref-optimization_values(rR, rG, rB))); 
[rR_opt, rG_opt, rB_opt] = fmincon(J,initial_guess,[], []) 

Is it possible to give fmincon 3 parameters for optimizing? I tried it with only one parameter and my code works perfectly then, but with 3 it always gives me the following error:



Not enough input arguments.
Error in
Optimization_3wires>@(rR,rG,rB)sum(abs(X_ref-optimization_values(rR,rG,rB)))

Error in fmincon (line 535)
      initVals.f = feval(funfcn{3},X,varargin{:});

Error in Optimization_3wires_Test5 (line 160)
r = fmincon(J,initial_guess,A,b,Aeq,beq)

Caused by:
    Failure in initial objective function evaluation.
    FMINCON cannot continue.


Thanks anyway and merry christmas,
Anne
0
Aensche
12/20/2016 3:05:03 PM
comp.soft-sys.matlab 211264 articles. 25 followers. lunamoonmoon (257) is leader. Post Follow

2 Replies
646 Views

Similar Articles

[PageSpeed] 46

"Aensche" <st102132@stud.uni-stuttgart.de> wrote in message <o3bhav$qf4$1@newscl01ah.mathworks.com>...
> hi everybody,
> 
> I would like to use fmincon to optimize a cost function by optimizing 3 parameters.
> 
> This is basicly the code I'm using:
> 
> initial_guess = [refR; refG; refB] 
> J = @(rR, rG, rB) sum(abs(X_ref-optimization_values(rR, rG, rB))); 
> [rR_opt, rG_opt, rB_opt] = fmincon(J,initial_guess,[], []) 
> 
> Is it possible to give fmincon 3 parameters for optimizing? I tried it with only one parameter and my code works perfectly then, but with 3 it always gives me the following error:
> 
> 
> 
> Not enough input arguments.
> Error in
> Optimization_3wires>@(rR,rG,rB)sum(abs(X_ref-optimization_values(rR,rG,rB)))
> 
> Error in fmincon (line 535)
>       initVals.f = feval(funfcn{3},X,varargin{:});
> 
> Error in Optimization_3wires_Test5 (line 160)
> r = fmincon(J,initial_guess,A,b,Aeq,beq)
> 
> Caused by:
>     Failure in initial objective function evaluation.
>     FMINCON cannot continue.
> 
> 
> Thanks anyway and merry christmas,
> Anne

Hi Anne,

I had faced the same problem recently and I was able to mitigate the problem.

Error "Not enough input arguments" is mainly because you are not defining enough input parameters to the fmincon function. The syntax is x = fmincon(fun,x0,A,b), so you need to define your Initial point. 

It would be great if you could post your code here, so that I can help you better. 

Regards,
Rao208
0
Vanditha
12/20/2016 3:23:03 PM
On 12/20/2016 10:05 AM, Aensche wrote:
> hi everybody,
>
> I would like to use fmincon to optimize a cost function by optimizing 3
> parameters.
>
> This is basicly the code I'm using:
>
> initial_guess = [refR; refG; refB] J = @(rR, rG, rB)
> sum(abs(X_ref-optimization_values(rR, rG, rB))); [rR_opt, rG_opt,
> rB_opt] = fmincon(J,initial_guess,[], [])
> Is it possible to give fmincon 3 parameters for optimizing? I tried it
> with only one parameter and my code works perfectly then, but with 3 it
> always gives me the following error:
>
>
>
> Not enough input arguments.
> Error in
> Optimization_3wires>@(rR,rG,rB)sum(abs(X_ref-optimization_values(rR,rG,rB)))
>
>
> Error in fmincon (line 535)
>      initVals.f = feval(funfcn{3},X,varargin{:});
>
> Error in Optimization_3wires_Test5 (line 160)
> r = fmincon(J,initial_guess,A,b,Aeq,beq)
>
> Caused by:
>    Failure in initial objective function evaluation.
>    FMINCON cannot continue.
>
>
> Thanks anyway and merry christmas,
> Anne

Perhaps the documentation on writing objective functions can help:
http://www.mathworks.com/help/optim/ug/writing-scalar-objective-functions.html

Alan Weiss
MATLAB mathematical toolbox documentation
0
Alan
12/21/2016 2:44:55 PM
Reply: