Why did I get two different results in nonlinear programing problems

2 views (last 30 days)
clear,clc
A = [1 4 5
4 2 6
5 6 3];
prob = optimproblem;
x = optimvar('x',3);
con = sum(x.^2) == 1;
prob.Constraints.con = con;
prob.Objective = x'*A*x;
x0.x = zeros(3,1);
% x0.x = rand(3,1);
show(prob)
OptimizationProblem : Solve for: x minimize : x(1)^2 + 2*x(2)^2 + 3*x(3)^2 + 4*x(2)*x(1) + 4*x(1)*x(2) + 6*x(3)*x(2) + 6*x(2)*x(3) + 5*x(3)*x(1) + 5*x(1)*x(3) subject to con: sum(x.^2) == 1
[sol,fval,flag,out] = solve(prob,x0)
Solving problem using fmincon. Converged to an infeasible point. fmincon stopped because the size of the current step is less than the value of the step size tolerance but constraints are not satisfied to within the value of the constraint tolerance. Consider enabling the interior point method feasibility mode.
sol = struct with fields:
x: [3x1 double]
fval = 0
flag =
NoFeasiblePointFound
out = struct with fields:
iterations: 1 funcCount: 2 constrviolation: 1 stepsize: 0 algorithm: 'interior-point' firstorderopt: 0 cgiterations: 0 message: 'Converged to an infeasible point....' bestfeasible: [] objectivederivative: "closed-form" constraintderivative: "closed-form" solver: 'fmincon'
sol.x
ans = 3x1
0 0 0
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
when the initial point is zeres(0),fval is 0,sol.x is [0;0;0].
but when it is rand(3,1),fval is -3.66.
I can't understand this reason

Answers (2)

Torsten
Torsten on 22 Jul 2024
Moved: Steven Lord on 22 Jul 2024
As you can see from the solver message, with x0 = [0 0 0], fmincon converged to an infeasible point. So you didn't get a solution, but "fmincon" failed.

John D'Errico
John D'Errico on 22 Jul 2024
Edited: John D'Errico on 22 Jul 2024
You have a nonlinear problem. You need to understand that given any set of starting values, an optimizer will sometimes find a solution though it need not always find the same solution since nonlinear problems will often have multiple solutions, sometimes it will get stuck at a non-solution but unable to find someplae better to look from that point, and thirdly, sometimes it will fail to go anywhere, being unable to even find a feasible point to begin iterations.
When you started the solver at all zeros, it got stuck, in the last mode. I might point out that all zeros is often the worst possible place to start a nonlinear solver.
Remember that nonlinear solvers are not some god-like computational beings, always able to solve any problem. They are far closer to my oft used example of a blind person placed on the earth at some point, and then asked to find the point of lowest elevation. The only gear this person is given is a cane to determine a direction to look next, and an altimeter to learn the current elevation. (Ok, some scuba gear might be nice too.) But clearly this individual will often fail to find a viable point, and unless your initial point is a good one, they will often fail to find the globally best location, in the depths of the Pacific Ocean.

Categories

Find more on Biological and Health Sciences in Help Center and File Exchange

Products


Release

R2020b

Community Treasure Hunt

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

Start Hunting!