[SOLVED] Passing additional arguments through function handle in Matlab

Issue

I have a function to optimize, say Function, in Matlab. This function depends on variables (say x) over which I want to optimize and one parameter (say, Q) which does not need to be optimized.Hence, the function Function(x,Q). In other words, I have an array of values for Q and want to find optimal x values for each Q. However, I cannot find a way how to pass those Q values when using function handle @Function in optimization function.

So, my question is how to pass those Q values when using function handle in optimization functions, for example fmincon(@Function,x0,A,b)?

Solution

Try using anonymous function:

x = cell( 1, numel(Q) );
for qi = 1:numel( Q )
   x{qi} = fmincon( @(x) Function(x, Q(qi)), A, b );
end 

Answered By – Shai

Answer Checked By – Timothy Miller (BugsFixing Admin)

Leave a Reply

Your email address will not be published. Required fields are marked *