# Why did I get two different results in nonlinear programing problems

조회 수: 3 (최근 30일)
Rudolf 2024년 7월 22일
편집: John D'Errico 2024년 7월 22일
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

댓글을 달려면 로그인하십시오.

### 답변 (2개)

Torsten 2024년 7월 22일
이동: Steven Lord 2024년 7월 22일
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.
##### 댓글 수: 0이전 댓글 -2개 표시이전 댓글 -2개 숨기기

댓글을 달려면 로그인하십시오.

John D'Errico 2024년 7월 22일
편집: John D'Errico 2024년 7월 22일
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.

댓글을 달려면 로그인하십시오.

### 카테고리

Help CenterFile Exchange에서 Mathematics and Optimization에 대해 자세히 알아보기

R2020b

### Community Treasure Hunt

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

Start Hunting!

Translated by