optimization error ,when i used fmincon for three variables,getting same intial guess value in result
1 回表示 (過去 30 日間)
古いコメントを表示
clear all
close all
xo=[0.0011,0.0049,0.36]; % assumptions
%nvars=5;
A=[];
b=[];
Aeq=[];
beq=[];
lb=[0.001,0.002,0.01]; %lower bound
ub=[0.01,0.08,0.5]; %upper bound
nonlincon = @(X)constraint_new(X); % calling constraint function
Fitnessfun=@(X)weight_testvariable(X); %calling objective function
options = optimoptions(@fmincon,'Display','iter-detailed','Algorithm','sqp','MaxIterations',1500)
[X,fval]=fmincon(Fitnessfun,xo,[],[],[],[],lb,ub,nonlincon,options)
baically i got same value of my intial guess value,not all only 1st and 3rd variables.i know these value depend on constraint and objective function
1 件のコメント
採用された回答
Walter Roberson
2019 年 8 月 19 日
function [fval]=weight_testvariable(X)
[...]
X=[0.001;0.006;0.4];
You are ignoring the input and always calculating the same thing.
If you were to not ignore the inputs, then:
thick_i=0.0014-X(1);
thick_o=0.0075-X(2);
Those would become 0 when X(1) become 0.0014 and 0.0075 . Your fval calculation multiplies the first term by thick_i and the second term by thick_o so the two terms can both become exactly 0 . Is it possible to do better? Perhaps, since weight_testvariable(ub) comes out negative.
So then let us try
X = sym('x', [1 3]);
[c,ceq] = constraint_new(X)
c =
[ x1 - 7/5000, x2 - 3/400, 27/5000 - x2]
ceq =
-3.24490449304822
Woah! Why did ceq, the equality constraint, come out as a value that is independent of the inputs [x1,x2,x3] ?
function [c,ceq] = constraint_new(X)
D_i=X(1);D_io=.0014;D_o=X(2);D_oo=.0075;L=X(3);
Looks like the input is being coped into D_* variables,
ceq =[heatload1_new(D_i,D_io,D_o,D_oo,L)-Qreq];
and the D_* variables are being passed into heatload1_new, so the problem must be in heatload1_new
function [Q]=heatload1_new(D_i,D_io,D_o,D_oo,L)
so the D_* variables make it to inside heatload1_new
X=[0.001;0.006;0.4];
X=[X(1);X(2);X(3)];
D_i=X(1);
D_io=.0014;
D_o=X(2);
D_oo=.0075;
L=X(3);
... and you create a vector of constant X values and use those constants to overwrite the D_* variables. So the D_* variable values that were passed into heatload1_new() become irrelevant and heatload1_new() always returns the same value independent of its inputs. Therefore the ceq constraint always ends up calculating the same thing independent of the inputs to the nonlinear constraint function. And that value is about -3.24, which can never be 0, so it is impossible for the equality constraint to be satisfied.
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Get Started with Optimization Toolbox についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!