Why did I get two different results in nonlinear programing problems
2 次查看(过去 30 天)
显示 更早的评论
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)
[sol,fval,flag,out] = solve(prob,x0)
sol.x
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
0 个评论
回答(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 个评论
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.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Biological and Health Sciences 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!