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!