fmincon function with vector inputs of different lengths?
3 views (last 30 days)
Show older comments
Abbi Hashem
on 28 Jun 2019
Answered: Walter Roberson
on 29 Jun 2019
The general form of the function I'll be using is:
x= fmincon(objective, x0,A,b, Aeq,beq, lb,ub ,nonlcon);
YET the input are vectors and matricies of different lengths ( for example, I have 2 vectors that are 1 by 8 and one matrix that is 8 by 1000).
So my question is what is the correct way to type in the x0? I have tried an array, where each cell contains one vector, but it didn't work
0 Comments
Accepted Answer
Walter Roberson
on 29 Jun 2019
If the inputs are effectively constants for a minimization (such as weights that are given for a situation) then they should not form part of x and you should instead parameterize the function call
@(x)objective(x, a, b, c, d)
Where a b c d are the extra inputs
If instead your input x0 values all represent variables whose best value is to be found to minimize the function, then you need to bundle them all together into a single input variable
function cost = objective(allinputs)
a = allinputs(1:4);
b = reshape(allinputs(5:16),4,3);
With x0 = [a0(:) ; b0(:)] ;
0 Comments
More Answers (0)
See Also
Categories
Find more on Systems of Nonlinear Equations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!