fmincon function with vector inputs of different lengths?
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
Abbi Hashem
il 28 Giu 2019
Risposto: Walter Roberson
il 29 Giu 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 Commenti
Risposta accettata
Walter Roberson
il 29 Giu 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 Commenti
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Operators and Elementary Operations in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!