Prev: problem with subsets
Next: isNaN
From: Mike Karr on 27 Apr 2010 13:02 Sanjeev Rao wrote: > Hello everyone, > > I am using FMINCON, and I am trying to pass a variable computed in the > objective function file to the non linear constraint file. This is > because the variable I want to pass is dependent on the design parameter > which is being optimized. Both the computed variable and the design > parameter are needed in the constraint file to satisfy a nonlinear > constraint. > > > However, I am at a loss trying to figure out how to pass the extra > variable which is computed each time the optimizer runs, in addition to > the design parameter. Any help on this would be greatly appreciated. > > I tried to look at nested and anonymous functions, but the examples > listed show the extra parameters as constants, and hence can be passed > from the fmincon calling file itself. > > Any help on this would be greatly appreciated. Sorry for being late on this, I'm behind on CSSM. Put the call on fmincon in an outer function, and establish the variable, let's call it V, as a variable in this function. Then, defined both the objective function and the constraint function within the same outer function, where they can "see" V. The overall structure will look something like: function r = outer V = ...; % define V here function y = objective(X) ... % use V in this body end function [cceq] = constraint(X) ... % also use V in this body end r = fmincon(@objective,...,@constraint,...) end hth, mike
|
Pages: 1 Prev: problem with subsets Next: isNaN |