Passing additional arguments through a function descriptor in Matlab

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

So my question is how to pass these Q values ​​when using a function descriptor in optimization functions like fmincon (@Function, x0, A, b)?

+5
source share
2

:

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

MATLAB, 3 :


  • Shai .
  • :
    , , .
    , MATLAB: function [x,fval] = runnested(a,b,c,x0) [x,fval] = fminunc(@nestedfun,x0); % Nested function that computes the objective function function y = nestedfun(x) y = (a - b*x(1)^2 + x(1)^4/3)*x(1)^2 + x(1)x(2) +... (-c + cx(2)^2)*x(2)^2; end end

  • , global , .
    MATLAB:
    • : function y = globalfun(x) global a b c y = (a - b*x(1)^2 + x(1)^4/3)*x(1)^2 + x(1)x(2) + ... (-c + cx(2)^2)*x(2)^2; end
    • : global a b c; a = 4; b = 2.1; c = 4; % Assign parameter values x0 = [0.5,0.5]; [x,fval] = fminunc(@globalfun,x0)
+4

All Articles