MATLAB: How to use patternsearch to optimize two control vectors of a function; optimizing both variables instead of passing one of them

optimization with patternserach

Dear Alan, I have an optimization problem where my function has two control variables as the following
function [NetPV,finalSupply] = OptimizedRate (Weights,NRates)
Weights and NRates are vectors as: Weights = [x1 x2 x3] and NRates = [y1 y2 y3]
I want to optimized Weights and NRates not just passing one of them. I have seen some examples like: https://uk.mathworks.com/help/optim/ug/passing-extra-parameters.html
and tried them. However this pass NRates variable instead of optimizing it. [x,fval,exitflag,output] = patternsearch(@(Weights)OptimizedRate(Weights,NRates),x0,[],[],Aeq,beq,LB,UB,options);
I'm looking for away to optimize Weights and NRates variables jointly.
Thanks for your help!

Best Answer

patternsearch(@(x)OptimizedRate(x(1),x(2)), [weight0 nRate0], ...
Index into one variable that is passed to the objective function.