MATLAB Answers

0

fmincon function with vector inputs of different lengths?

Asked by Abbi Hashem on 28 Jun 2019
Latest activity Answered by 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

Sign in to comment.

1 Answer

Answer by Walter Roberson
on 29 Jun 2019
 Accepted Answer

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

Sign in to comment.