# Why is MATLAB giving me a wrong answer when solving a minimization problem?

1. Jan 25, 2013

### math8

In MATLAB, I am using fmincon to solve a minimization problem with nonlinear constraints. The problem is that, it is giving me a wrong answer, a point that is not a minimizer (not even close), and that is not within the tolerance. I made sure to use a feasible initial point.

However, when I use another initial feasible point, it gives me a correct answer.

Here is the problem:

min f = 100*(x(2)-x(1)^2)^2+(1-x(1))^2;
s.t. constraints= [1-(x(1)*x(2));-x(1)-(x(2))^2;x(1)-0.5] <= 0

The minimizer is [0.5 ; 2] with optimal objective value: 306.5000

However when I use the feasible initial point x0=[-1 ; -2], this gives me the answer: [-0.7921; -1.2624] (which is not feasible and has an f value of 360.3798 !!) (to within options.TolCon = 1e-06)

and when I use the initial point x0=[0.4;4], this gives me the correct answer [0.5 ; 2].

Note that my constraints do not require the variables to be non-negative.

Any idea what I am doing wrong here?

2. Jan 26, 2013

### NemoReally

You're not doing anything "wrong" , but you are being given a demonstration of the potential limitations of optimization algorithms and the need to choose the starting point carefully. I don't have Matlab so I've implemented your function in Mathcad and used its Solve Block capability to minimize the function given the constraints.

If you look at the left hand plot in image below you should see black contour lines (the function), two clusters of blue contour lines (the constraint boundaries) and 4 coloured dots (2 initial points and 2 solutions).

You should note that the first 'incorrect' minimum is within the larger constrained area of the x-y plane and the solution has migrated towards the constraint boundary. The right hand plot may show the descent slightly more clearly. What's happened is that the minimization algorithm (Conjugate Gradient) hits the constraint if it tries to move further down the function slope, so it halts with the best value it can find (which has strayed slightly over the boundary).

The 'correct' minimum starts from the second constrained area and follows the same process of descending the slope until it hits the boundary and can't progress any further. It also is just over the boundary. (The algorithms don't necessarily treat constraints as hard conditions but will try to meet them as closely as possible).

A useful technique is to plot your function first to get a feel for where to start - you may even need to calculate it for several points and choose the minimum.

#### Attached Files:

• ###### phys - 13 01 26 optimization 01.jpg
File size:
51.8 KB
Views:
291
Last edited: Jan 26, 2013