fmincon: how should x0 be specified

I want to minimize a multivariable uncontstrained function with lower and upper bounds. I don't have any information or idea how to define x0 as initial values and cannot accept zero values.Here is the code
obj = @(x) (1-x(1))*(5*x(2)^3+x(2)^2) + x(1)*(0.2*x(2)^3+1.2*x(2)^2);
x0=ones(0,30);
[x,fval] = fmincon(obj,x0,[],[],[],[],[0;30],[1;50])
How should the x0 be specified regarding the bounds of the variables?

 Accepted Answer

The way you specified ‘x0’, it is a ‘0×30 empty double matrix’!
I would specify it as the median of the bounds, so here:
lb = [0;30];
ub = [1;50];
x0 = median([lb ub],2);
producing:
x0 =
0.5000
40.0000

3 Comments

Thank you for the answer, it runs now. Can anyone specify how is x0 determined? In the documentation it writes that it is the initial values of x, but what if it is 0?
x0 is a value that you arbitrarily set. So you can decide whether it is 0 or not. Usually, a value is chosen that you think is senseful and close to the solution.
@Torsten — Thank you.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!