fmincon function with vector inputs of different lengths?

1 次查看(过去 30 天)
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

采纳的回答

Walter Roberson
Walter Roberson 2019-6-29
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 个)

类别

Help CenterFile Exchange 中查找有关 Systems of Nonlinear Equations 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by