When I use fmincon, the optimised result does not satisfy my non li... (2024)

17 views (last 30 days)

Show older comments

Tianshu Gao on 29 Aug 2023

  • Link

    Direct link to this question

    https://support.mathworks.com/matlabcentral/answers/2014216-when-i-use-fmincon-the-optimised-result-does-not-satisfy-my-non-liner-constraints

  • Link

    Direct link to this question

    https://support.mathworks.com/matlabcentral/answers/2014216-when-i-use-fmincon-the-optimised-result-does-not-satisfy-my-non-liner-constraints

Commented: Matt J on 30 Aug 2023

Open in MATLAB Online

clear variables

close all

clc

fun = @(x)4*x(1)+x(2);

x0=[0.4,0.28]

x0 = 1×2

0.4000 0.2800

lb = [0.01,0.01];

ub = [5,0.8];

A = [];

b = [];

Aeq = [];

beq = [];

options = optimoptions('fmincon','Algorithm','sqp');

c = @(x)(4+4*x(1)+9*x(1)^2)*(1+x(1))^2-(2*x(1)^3*x(2)+2+3*x(1)+3*x(1)^2)^2+0.001;

nonlcon = @(x)deal(c(x),[]);

[x,fval,exitflag,output] = fmincon(fun,x0,A,b,Aeq,beq,lb,ub,nonlcon,options);

Feasible point with lower objective function value found.Converged to an infeasible point.fmincon stopped because the size of the current step is less thanthe value of the step size tolerance but constraints are notsatisfied to within the value of the constraint tolerance.

exitflag

exitflag = -2

checkinitialpoint=(4+4*x0(1)+9*x0(1)^2)*(1+x0(1))^2-(2*x0(1)^3*x0(2)+2+3*x0(1)+3*x0(1)^2)^2+0.001;

checkconstraits=(4+4*x(1)+9*x(1)^2)*(1+x(1))^2-(2*x(1)^3*x(2)+2+3*x(1)+3*x(1)^2)^2+0.001;

The above is my matlab code, I input the nonlear constraints, but the results give to me is obviously not satisfy the constraints (you can see that checkconstraits is positive), my initial point is within the range.

Can anyone help me? Many thanks.

1 Comment

Show -1 older commentsHide -1 older comments

Torsten on 29 Aug 2023

Direct link to this comment

https://support.mathworks.com/matlabcentral/answers/2014216-when-i-use-fmincon-the-optimised-result-does-not-satisfy-my-non-liner-constraints#comment_2864801

  • Link

    Direct link to this comment

    https://support.mathworks.com/matlabcentral/answers/2014216-when-i-use-fmincon-the-optimised-result-does-not-satisfy-my-non-liner-constraints#comment_2864801

The solver converged to an infeasible point (see above). Your observation is the same as the exitflag from "fmincon" indicates.

Sign in to comment.

Sign in to answer this question.

Answers (2)

Alan Weiss on 29 Aug 2023

  • Link

    Direct link to this answer

    https://support.mathworks.com/matlabcentral/answers/2014216-when-i-use-fmincon-the-optimised-result-does-not-satisfy-my-non-liner-constraints#answer_1296326

  • Link

    Direct link to this answer

    https://support.mathworks.com/matlabcentral/answers/2014216-when-i-use-fmincon-the-optimised-result-does-not-satisfy-my-non-liner-constraints#answer_1296326

Open in MATLAB Online

You would do better to use the default 'interior-point' algorithm, which arrives at a feasible solution.

fun = @(x)4*x(1)+x(2);

x0=[0.4,0.28];

lb = [0.01,0.01];

ub = [5,0.8];

A = [];

b = [];

Aeq = [];

beq = [];

% options = optimoptions('fmincon','Algorithm','sqp');

c = @(x)(4+4*x(1)+9*x(1)^2)*(1+x(1))^2-(2*x(1)^3*x(2)+2+3*x(1)+3*x(1)^2)^2+0.001;

nonlcon = @(x)deal(c(x),[]);

[x,fval,exitflag,output] = fmincon(fun,x0,A,b,Aeq,beq,lb,ub,nonlcon)

Feasible point with lower objective function value found.Local minimum found that satisfies the constraints.Optimization completed because the objective function is non-decreasing in feasible directions, to within the value of the optimality tolerance,and constraints are satisfied to within the value of the constraint tolerance.

x = 1×2

0.1004 0.5349

fval = 0.9363

exitflag = 1

output = struct with fields:

iterations: 51 funcCount: 199 constrviolation: 0 stepsize: 2.4326e-07 algorithm: 'interior-point' firstorderopt: 5.5041e-07 cgiterations: 4 message: 'Local minimum found that satisfies the constraints.↵↵Optimization completed because the objective function is non-decreasing in ↵feasible directions, to within the value of the optimality tolerance,↵and constraints are satisfied to within the value of the constraint tolerance.↵↵<stopping criteria details>↵↵Optimization completed: The relative first-order optimality measure, 1.376030e-07,↵is less than options.OptimalityTolerance = 1.000000e-06, and the relative maximum constraint↵violation, 0.000000e+00, is less than options.ConstraintTolerance = 1.000000e-06.' bestfeasible: [1×1 struct]

For more information about dealing with infeasible solutions, see Solver Lost Feasibility.

Alan Weiss

MATLAB mathematical toolbox documentation

1 Comment

Show -1 older commentsHide -1 older comments

Tianshu Gao on 30 Aug 2023

Direct link to this comment

https://support.mathworks.com/matlabcentral/answers/2014216-when-i-use-fmincon-the-optimised-result-does-not-satisfy-my-non-liner-constraints#comment_2865941

  • Link

    Direct link to this comment

    https://support.mathworks.com/matlabcentral/answers/2014216-when-i-use-fmincon-the-optimised-result-does-not-satisfy-my-non-liner-constraints#comment_2865941

Thank you

Sign in to comment.

Matt J on 29 Aug 2023

  • Link

    Direct link to this answer

    https://support.mathworks.com/matlabcentral/answers/2014216-when-i-use-fmincon-the-optimised-result-does-not-satisfy-my-non-liner-constraints#answer_1296441

  • Link

    Direct link to this answer

    https://support.mathworks.com/matlabcentral/answers/2014216-when-i-use-fmincon-the-optimised-result-does-not-satisfy-my-non-liner-constraints#answer_1296441

Edited: Matt J on 29 Aug 2023

Open in MATLAB Online

Since it is a 2D problem, it practically begs you to pre-sweep for a good initial guess:

fun = @(x)4*x(1)+x(2);

lb = [0.01,0.01];

ub = [5,0.8];

A = [];

b = [];

Aeq = [];

beq = [];

c = @(x)(4+4*x(1)+9*x(1)^2)*(1+x(1))^2-(2*x(1)^3*x(2)+2+3*x(1)+3*x(1)^2)^2+0.001;

nonlcon = @(x)deal(c(x),[]);

[x0,fval0]=sweep(fun,c,lb,ub)

x0 = 1×2

0.1821 0.4186

fval0 = 1.1469

options = optimoptions('fmincon','Algorithm','sqp');

[x,fval,exitflag,output] = fmincon(fun,x0,A,b,Aeq,beq,lb,ub,nonlcon,options);

Local minimum possible. Constraints satisfied.fmincon stopped because the size of the current step is less thanthe value of the step size tolerance and constraints are satisfied to within the value of the constraint tolerance.

x,fval

x = 1×2

0.1004 0.5349

fval = 0.9363

function [x0,fval]=sweep(fun,c,lb,ub)

F=@(x1,x2) fun([x1,x2])+eps./(c([x1,x2])<=0);

[X1,X2]=ndgrid(linspace(lb(1),ub(1),30), linspace(lb(2),ub(2),30));

v=arrayfun(F,X1,X2);

[fval,i]=min(v(:));

if ~isfinite(fval)

disp 'No feasible point found'; x0=[];

else

x0=[X1(i),X2(i)];

end

end

2 Comments

Show NoneHide None

Tianshu Gao on 30 Aug 2023

Direct link to this comment

https://support.mathworks.com/matlabcentral/answers/2014216-when-i-use-fmincon-the-optimised-result-does-not-satisfy-my-non-liner-constraints#comment_2865946

  • Link

    Direct link to this comment

    https://support.mathworks.com/matlabcentral/answers/2014216-when-i-use-fmincon-the-optimised-result-does-not-satisfy-my-non-liner-constraints#comment_2865946

Thank you.

Matt J on 30 Aug 2023

Direct link to this comment

https://support.mathworks.com/matlabcentral/answers/2014216-when-i-use-fmincon-the-optimised-result-does-not-satisfy-my-non-liner-constraints#comment_2866401

  • Link

    Direct link to this comment

    https://support.mathworks.com/matlabcentral/answers/2014216-when-i-use-fmincon-the-optimised-result-does-not-satisfy-my-non-liner-constraints#comment_2866401

You're welcome, but please Accept-click whichever answer solved your issue.

Sign in to comment.

Sign in to answer this question.

See Also

Categories

Mathematics and OptimizationOptimization ToolboxOptimization ResultsSolver Outputs and Iterative Display

Find more on Solver Outputs and Iterative Display in Help Center and File Exchange

Tags

  • fmincon nonlcon

Community Treasure Hunt

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

Start Hunting!

An Error Occurred

Unable to complete the action because of changes made to the page. Reload the page to see its updated state.


When I use fmincon, the optimised result does not satisfy my non li... (8)

Select a Web Site

Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .

You can also select a web site from the following list

Americas

  • América Latina (Español)
  • Canada (English)
  • United States (English)

Europe

  • Belgium (English)
  • Denmark (English)
  • Deutschland (Deutsch)
  • España (Español)
  • Finland (English)
  • France (Français)
  • Ireland (English)
  • Italia (Italiano)
  • Luxembourg (English)
  • Netherlands (English)
  • Norway (English)
  • Österreich (Deutsch)
  • Portugal (English)
  • Sweden (English)
  • Switzerland
    • Deutsch
    • English
    • Français
  • United Kingdom(English)

Asia Pacific

Contact your local office

When I use fmincon, the optimised result does not satisfy my non li... (2024)
Top Articles
Latest Posts
Article information

Author: Sen. Ignacio Ratke

Last Updated:

Views: 5733

Rating: 4.6 / 5 (76 voted)

Reviews: 91% of readers found this page helpful

Author information

Name: Sen. Ignacio Ratke

Birthday: 1999-05-27

Address: Apt. 171 8116 Bailey Via, Roberthaven, GA 58289

Phone: +2585395768220

Job: Lead Liaison

Hobby: Lockpicking, LARPing, Lego building, Lapidary, Macrame, Book restoration, Bodybuilding

Introduction: My name is Sen. Ignacio Ratke, I am a adventurous, zealous, outstanding, agreeable, precious, excited, gifted person who loves writing and wants to share my knowledge and understanding with you.