Problem in solving fmincon (2024)

Fevzi

2012-05-31 22:48:45 UTC

Permalink

Hello,

I want to solve a nonlinear constrained optimization problem. I prepared 3 m-files which are for constraints, objective function and calling optimization toolbox.

M-File to call the tool box is following:

lb = [12.5;0.000460;0.005];
ub = [75;0.000786;0.160];
A =[];
Aeq= [];
b = [];
beq = [];
x0= [32;0.00058;0.1];
[x,fval,exitflag,output] = fmincon(@microobj,x0,A,b,Aeq,beq,lb,ub,@microcons)
[c,ceq] = microcons(x)

M-File for constraints is following:

function [c,ceq] = microcons(x)

b1 = -152.103;
b2 = 2.16514;
b3 = 1113.81;
b4 = 204245;
b5 = -0.0179843;
b6 = -3391.78;
b7 = -248075399;
b8 = -7.60179;
b9 = 1242.21;
b10 = -45237.6;
w = 0.500;
n = w/x(3);
D = 0.4;
N = (x(1)*1000)/(pi*D);
vL = 12.5;
vU = 75;
fzL = 0.000460;
fzU = 0.000786;
DocL = 0.005;
DocU = 0.160;
TlL = 0;
TlU = 20.5;
nL = 10000;
nU = 60000;

Tl = b1+x(1)*b2+x(3)*b3+x(2)*b4+(x(1)^2)*b5+(x(3)^2)*b6+(x(2)^2)*b7+x(1)*x(3)*b8+x(1)*x(2)*b9+x(2)*x(3)*b10;

c = [vL-x(1);x(1)-vU;fzL-x(2);x(2)-fzU;DocL-x(3);x(3)-DocU;TlL-Tl;Tl-TlU;nL-N;N-nU];

ceq = [(n*x(3))-w];

M-File for objective function is following:

function f = microobj(x)

b1 = -152.103;
b2 = 2.16514;
b3 = 1113.81;
b4 = 204245;
b5 = -0.0179843;
b6 = -3391.78;
b7 = -248075399;
b8 = -7.60179;
b9 = 1242.21;
b10 = -45237.6;

ae = 0.7;
D = 0.4;
A = 3.2;
k = (A-D)/(2*ae*D);
L = ((4*k*(k+1)*ae*D) + (2*ae*D));
dL = (k-1)*sqrt(2)*ae*D;
Lc = L + dL;
Lr = (sqrt(2)*(A-D))/2;
w = 0.500;
n = w/x(3);
N = (x(1)*1000)/(pi*D);
z = 2;

frCut = x(2)*z*N;

Tl = b1+x(1)*b2+x(3)*b3+x(2)*b4+(x(1)^2)*b5+(x(3)^2)*b6+(x(2)^2)*b7+x(1)*x(3)*b8+x(1)*x(2)*b9+x(2)*x(3)*b10;

Tm = (Lc/frCut)*n;

c0 = 1;
CM = c0* Tm;

Ts = 3;
CS = c0*Ts;

Tc = 3;
CR = c0*Tc*(ceil(Tm/Tl));

tC = 50;
CT = tC*(ceil(Tm/Tl));

f = CM + CS + CR + CT;

However, the tool box ignores "TlL = 0; TlU = 20.5;" limits and finds a negative Tl value. (When the solution is found, the value of 7th row in c vector is positive instead of negative. When I calculated Tl value using x1, x2, x3 and b1 to b10 values, Tl value is sufficiently large negative number). Then I wrote "TlL = 0.0000000001;" (1*10^-10) instead of "TlL = 0;", toolbox finds a reasonable result. Finally I increased the decimals to test whether toolbox always consider the TlL limit or not. When I tested the program for "TlL = 0.0000000000000001;" (1*10^-16), the program again gives a problematic result. I couldn't understand the reason of this problem. If it was a problem with # of decimal digits, it should not give a reasonable results for 1*(10^(-15)) or 1*(10^(-13))

Best Regards,

Matt J

2012-05-31 23:03:12 UTC

Permalink

Post by Fevzi
Hello,
I want to solve a nonlinear constrained optimization problem. I prepared 3 m-files which are for constraints, objective function and calling optimization toolbox.
lb = [12.5;0.000460;0.005];
ub = [75;0.000786;0.160];
A =[];
Aeq= [];
b = [];
beq = [];
x0= [32;0.00058;0.1];
[c,ceq] = microcons(x)
function [c,ceq] = microcons(x)
b1 = -152.103;
b2 = 2.16514;
b3 = 1113.81;
b4 = 204245;
b5 = -0.0179843;
b6 = -3391.78;
b7 = -248075399;
b8 = -7.60179;
b9 = 1242.21;
b10 = -45237.6;
w = 0.500;
n = w/x(3);
D = 0.4;
N = (x(1)*1000)/(pi*D);
vL = 12.5;
vU = 75;
fzL = 0.000460;
fzU = 0.000786;
DocL = 0.005;
DocU = 0.160;
TlL = 0;
TlU = 20.5;
nL = 10000;
nU = 60000;
Tl = b1+x(1)*b2+x(3)*b3+x(2)*b4+(x(1)^2)*b5+(x(3)^2)*b6+(x(2)^2)*b7+x(1)*x(3)*b8+x(1)*x(2)*b9+x(2)*x(3)*b10;
c = [vL-x(1);x(1)-vU;fzL-x(2);x(2)-fzU;DocL-x(3);x(3)-DocU;TlL-Tl;Tl-TlU;nL-N;N-nU];
ceq = [(n*x(3))-w];
function f = microobj(x)
b1 = -152.103;
b2 = 2.16514;
b3 = 1113.81;
b4 = 204245;
b5 = -0.0179843;
b6 = -3391.78;
b7 = -248075399;
b8 = -7.60179;
b9 = 1242.21;
b10 = -45237.6;
ae = 0.7;
D = 0.4;
A = 3.2;
k = (A-D)/(2*ae*D);
L = ((4*k*(k+1)*ae*D) + (2*ae*D));
dL = (k-1)*sqrt(2)*ae*D;
Lc = L + dL;
Lr = (sqrt(2)*(A-D))/2;
w = 0.500;
n = w/x(3);
N = (x(1)*1000)/(pi*D);
z = 2;
frCut = x(2)*z*N;
Tl = b1+x(1)*b2+x(3)*b3+x(2)*b4+(x(1)^2)*b5+(x(3)^2)*b6+(x(2)^2)*b7+x(1)*x(3)*b8+x(1)*x(2)*b9+x(2)*x(3)*b10;
Tm = (Lc/frCut)*n;
c0 = 1;
CM = c0* Tm;
Ts = 3;
CS = c0*Ts;
Tc = 3;
CR = c0*Tc*(ceil(Tm/Tl));
tC = 50;
CT = tC*(ceil(Tm/Tl));
f = CM + CS + CR + CT;
However, the tool box ignores "TlL = 0; TlU = 20.5;" limits and finds a negative Tl value. (When the solution is found, the value of 7th row in c vector is positive instead of negative. When I calculated Tl value using x1, x2, x3 and b1 to b10 values, Tl value is sufficiently large negative number). Then I wrote "TlL = 0.0000000001;" (1*10^-10) instead of "TlL = 0;", toolbox finds a reasonable result. Finally I increased the decimals to test whether toolbox always consider the TlL limit or not. When I tested the program for "TlL = 0.0000000000000001;" (1*10^-16), the program again gives a problematic result. I couldn't understand the reason of this problem. If it was a problem with # of decimal digits, it should not give a reasonable results for 1*(10^(-15)) or 1*(10^(-13))

================

You haven't shown us the magnitude of the negative number, so there's no reason yet to think the negatives are significantly large. Was the constraint violated by an amount greater than the TolCon tolerance parameter?

Also, you also haven't shown us the exitflag output of FMINCON. It might tell you that convergence failed for some reason.

Finally, if it's important to you to satisfy the bounds all the time then try using the sqp algorithm, or the interior-point algorithm with the AlwaysHonorConstraints option active.

Fevzi

2012-06-02 08:57:28 UTC

Permalink

Post by Matt J

Post by Fevzi
Hello,
I want to solve a nonlinear constrained optimization problem. I prepared 3 m-files which are for constraints, objective function and calling optimization toolbox.
lb = [12.5;0.000460;0.005];
ub = [75;0.000786;0.160];
A =[];
Aeq= [];
b = [];
beq = [];
x0= [32;0.00058;0.1];
[c,ceq] = microcons(x)
function [c,ceq] = microcons(x)
b1 = -152.103;
b2 = 2.16514;
b3 = 1113.81;
b4 = 204245;
b5 = -0.0179843;
b6 = -3391.78;
b7 = -248075399;
b8 = -7.60179;
b9 = 1242.21;
b10 = -45237.6;
w = 0.500;
n = w/x(3);
D = 0.4;
N = (x(1)*1000)/(pi*D);
vL = 12.5;
vU = 75;
fzL = 0.000460;
fzU = 0.000786;
DocL = 0.005;
DocU = 0.160;
TlL = 0;
TlU = 20.5;
nL = 10000;
nU = 60000;
Tl = b1+x(1)*b2+x(3)*b3+x(2)*b4+(x(1)^2)*b5+(x(3)^2)*b6+(x(2)^2)*b7+x(1)*x(3)*b8+x(1)*x(2)*b9+x(2)*x(3)*b10;
c = [vL-x(1);x(1)-vU;fzL-x(2);x(2)-fzU;DocL-x(3);x(3)-DocU;TlL-Tl;Tl-TlU;nL-N;N-nU];
ceq = [(n*x(3))-w];
function f = microobj(x)
b1 = -152.103;
b2 = 2.16514;
b3 = 1113.81;
b4 = 204245;
b5 = -0.0179843;
b6 = -3391.78;
b7 = -248075399;
b8 = -7.60179;
b9 = 1242.21;
b10 = -45237.6;
ae = 0.7;
D = 0.4;
A = 3.2;
k = (A-D)/(2*ae*D);
L = ((4*k*(k+1)*ae*D) + (2*ae*D));
dL = (k-1)*sqrt(2)*ae*D;
Lc = L + dL;
Lr = (sqrt(2)*(A-D))/2;
w = 0.500;
n = w/x(3);
N = (x(1)*1000)/(pi*D);
z = 2;
frCut = x(2)*z*N;
Tl = b1+x(1)*b2+x(3)*b3+x(2)*b4+(x(1)^2)*b5+(x(3)^2)*b6+(x(2)^2)*b7+x(1)*x(3)*b8+x(1)*x(2)*b9+x(2)*x(3)*b10;
Tm = (Lc/frCut)*n;
c0 = 1;
CM = c0* Tm;
Ts = 3;
CS = c0*Ts;
Tc = 3;
CR = c0*Tc*(ceil(Tm/Tl));
tC = 50;
CT = tC*(ceil(Tm/Tl));
f = CM + CS + CR + CT;
However, the tool box ignores "TlL = 0; TlU = 20.5;" limits and finds a negative Tl value. (When the solution is found, the value of 7th row in c vector is positive instead of negative. When I calculated Tl value using x1, x2, x3 and b1 to b10 values, Tl value is sufficiently large negative number). Then I wrote "TlL = 0.0000000001;" (1*10^-10) instead of "TlL = 0;", toolbox finds a reasonable result. Finally I increased the decimals to test whether toolbox always consider the TlL limit or not. When I tested the program for "TlL = 0.0000000000000001;" (1*10^-16), the program again gives a problematic result. I couldn't understand the reason of this problem. If it was a problem with # of decimal digits, it should not give a reasonable results for 1*(10^(-15)) or 1*(10^(-13))

================
You haven't shown us the magnitude of the negative number, so there's no reason yet to think the negatives are significantly large. Was the constraint violated by an amount greater than the TolCon tolerance parameter?
Also, you also haven't shown us the exitflag output of FMINCON. It might tell you that convergence failed for some reason.
Finally, if it's important to you to satisfy the bounds all the time then try using the sqp algorithm, or the interior-point algorithm with the AlwaysHonorConstraints option active.

******************************************************************
Here is the Result of the program when "TlL = 0;"

Warning: Trust-region-reflective algorithm does not solve this type of problem,
using active-set algorithm. You could also try the interior-point algorithm: set
the Algorithm option to 'interior-point' and rerun.

Post by Matt J
In fmincon at 460

In micromultipassmillCALL at 17

Local minimum possible. Constraints satisfied.

fmincon stopped because the size of the current search direction is less than
twice the default value of the step size tolerance and constraints were
satisfied to within the default value of the constraint tolerance.

<stopping criteria details>

Active inequalities (to within options.TolCon = 1e-006):
lower upper ineqlin ineqnonlin
7

x =

38.6304
0.0007
0.1598

fval =

-5.4256e+008

exitflag =

4

output =

iterations: 17
funcCount: 198
lssteplength: 1
stepsize: 4.2554e-009
algorithm: 'medium-scale: SQP, Quasi-Newton, line-search'
firstorderopt: 3.6404e+016
constrviolation: 2.5720e-007
message: [1x770 char]

c =

-26.1303834688645
-36.3696165311355
-0.000231031509820056
-9.49684901799443e-05
-0.154763343633094
-0.00723665636690607
2.57203129905292e-07
-20.5000002572031
-20741.0824130261
-29258.9175869739

ceq =

************

Here is the Result of the program when "TlL = 0.0000000001;"

Warning: Trust-region-reflective algorithm does not solve this type of problem,
using active-set algorithm. You could also try the interior-point algorithm: set
the Algorithm option to 'interior-point' and rerun.

Post by Matt J
In fmincon at 460

In micromultipassmillCALL at 17

Local minimum possible. Constraints satisfied.

fmincon stopped because the size of the current search direction is less than
twice the default value of the step size tolerance and constraints were
satisfied to within the default value of the constraint tolerance.

<stopping criteria details>

No active inequalities.

x =

32.0000
0.0006
0.1000

fval =

62.0503

exitflag =

4

output =

iterations: 15
funcCount: 157
lssteplength: 0.5000
stepsize: 1.2611e-008
algorithm: 'medium-scale: SQP, Quasi-Newton, line-search'
firstorderopt: []
constrviolation: 0
message: [1x770 char]

c =

-19.5000000000000
-43
-0.000120000000000000
-0.000206000000000000
-0.0950000000000000
-0.0670000000000000
-7.34420137630000
-13.1557986236000
-15464.7908947033
-34535.2091052967

ceq =

Does the problem TolCon? If yes, how can I change TolCon to a smaller tolerance?
In order to use interior-point algorithm with AlwaysHonorConstraints, are the following lines sufficient or do I need to define AlwaysHonorConstraints in some place?

options = optimset('algorithm','interior-point');
[x,fval,exitflag,output] = fmincon(@micromultipassmillobj,x0,A,b,Aeq,beq,lb,ub,@micromultipassmillcons,options)

Sargondjani

2012-06-01 05:18:10 UTC

Permalink

just small advice on programming: i think it is more convenient to pass all your parameters into the two m-files (as inputs) instead of defining them inside your m-file. you can do it like this:

m-file:
function y=fun_obj(x,par1,par2...)

and then you define the values of par1, etc. before calling mfincon. you can call fmincon like this:

fmincon(@(x)fun_obj(x,par1,par,..),A,b,.....)

since you have quite a few parameters you can also store them in a structure:
par.b1=...
par.b2=...

and then your m-file can just just par as an input:
function y=fun_ob(x,par)

Problem in solving fmincon (2024)
Top Articles
Tyrone's Unblocked Games Among Us
Roboquest: How to Get Chromatic Cell | Unlocking Elementalist - Games Fuze
Custom Screensaver On The Non-touch Kindle 4
Cappacuolo Pronunciation
Caesars Rewards Loyalty Program Review [Previously Total Rewards]
Junk Cars For Sale Craigslist
Celebrity Extra
Bin Stores in Wisconsin
Www.politicser.com Pepperboy News
From Algeria to Uzbekistan-These Are the Top Baby Names Around the World
Crocodile Tears - Quest
Craigslist Parsippany Nj Rooms For Rent
سریال رویای شیرین جوانی قسمت 338
Hay day: Top 6 tips, tricks, and cheats to save cash and grow your farm fast!
What Happened To Father Anthony Mary Ewtn
Tv Schedule Today No Cable
World of White Sturgeon Caviar: Origins, Taste & Culinary Uses
Wisconsin Women's Volleyball Team Leaked Pictures
How do you like playing as an antagonist? - Goonstation Forums
Byte Delta Dental
Walmart Double Point Days 2022
Palm Coast Permits Online
The Ultimate Style Guide To Casual Dress Code For Women
Wausau Marketplace
Everything you need to know about Costco Travel (and why I love it) - The Points Guy
Swgoh Blind Characters
Eine Band wie ein Baum
Noaa Duluth Mn
Violent Night Showtimes Near Century 14 Vallejo
2013 Ford Fusion Serpentine Belt Diagram
Bjerrum difference plots - Big Chemical Encyclopedia
UMvC3 OTT: Welcome to 2013!
Hdmovie2 Sbs
Kimoriiii Fansly
27 Modern Dining Room Ideas You'll Want to Try ASAP
Geico Car Insurance Review 2024
My Reading Manga Gay
Greyson Alexander Thorn
Vlacs Maestro Login
Motor Mounts
Chase Bank Cerca De Mí
Sedano's Supermarkets Expands to Orlando - Sedano's Supermarkets
Streameast.xy2
Jail View Sumter
Gvod 6014
Davis Fire Friday live updates: Community meeting set for 7 p.m. with Lombardo
Cl Bellingham
Mathews Vertix Mod Chart
[Teen Titans] Starfire In Heat - Chapter 1 - Umbrelloid - Teen Titans
Craigslist Chautauqua Ny
Craigslist Indpls Free
How To Find Reliable Health Information Online
Latest Posts
Article information

Author: Prof. An Powlowski

Last Updated:

Views: 5353

Rating: 4.3 / 5 (64 voted)

Reviews: 95% of readers found this page helpful

Author information

Name: Prof. An Powlowski

Birthday: 1992-09-29

Address: Apt. 994 8891 Orval Hill, Brittnyburgh, AZ 41023-0398

Phone: +26417467956738

Job: District Marketing Strategist

Hobby: Embroidery, Bodybuilding, Motor sports, Amateur radio, Wood carving, Whittling, Air sports

Introduction: My name is Prof. An Powlowski, I am a charming, helpful, attractive, good, graceful, thoughtful, vast person who loves writing and wants to share my knowledge and understanding with you.