Problems with fmincon constraints writing

1 回表示 (過去 30 日間)
Saurabh Gupta
Saurabh Gupta 2019 年 3 月 26 日
コメント済み: Alan Weiss 2019 年 3 月 26 日
Hi all,
i am writing code to optimize my onstraint in given equation.
Capture.PNG
i have this E11 and E22 values which are array of (1793*1). when i have written this function as
fun=@(C) 0.5*C(1)*(exp(C(2)*E11.^2+2*C(3)*E11.*E22+C(4)*E22.^2)-1;
I am getting error that "fun should return a scalar value." i am lost here as my function is vector of (1793*1). To make it scalar do i need to use something. for now i am using "sum" for making this expression scalar. whole expression is written like
fun=@(C) sum(0.5*C(1)*(exp(C(2)*E11.^2+2*C(3)*E11.*E22+C(4)*E22.^2)-1);
by using this i am getting solution but optimized values are way out of leak. so please help out if anyone has any experiene working with fmincon.
Another query is related to constraint. i have written them like.
nonlcon = @constraint;
A= [-1,0,0,0; 0,-1,0,0; 0,0,0,0;0,0,0,-1];
B=[0;0;0;0];
C0= [1e-5, 2e-5, 3e-5,4.5e-5];
C = fmincon(fun,C0,A,B,[],[],[],[],nonlcon)
constraint is defined as
function [c,ceq] = constraint(C)
c = -C(2)*C(4)+C(3)^2;
ceq = [];
end
Have i written them correctly or require some modifications?
Any help will be appreciated.
Thanks
Saurabh

回答 (1 件)

Alan Weiss
Alan Weiss 2019 年 3 月 26 日
You should not use linear constraints that way. Instead, use bounds.
Your nonlinear constraint function looks fine.
The reason that the solver wants fun to return a scalar value is that is a requirement for ANY optimizer, in MATLAB or not. It is not sensible to try to minimize a function that is vector-valued. Here's why. If fun_1 decreases but fun_2 increases, are you better off? The answer is that you cannot say. For more information, see any literature on multiobjective optimization.
Alan Weiss
MATLAB mathematical toolbox documentation
  2 件のコメント
Saurabh Gupta
Saurabh Gupta 2019 年 3 月 26 日
Thanks for your quick reply.
i tried with bounds writing them like
lb=[0,0,-inf,0];
ub=[inf,inf,inf,inf];
fun=@(C) sum(0.5*C(1)*(exp(C(2)*Strain_11.^2+2*C(3)*Strain_11.*Strain_22+C(4)*Strain_22.^2)-1));
still facing same issue.
one more thing about fmincon. if i use lsqnonlin then i can fit this equation but i have to forget my constraints then fmincon should also work in this way as we are just adding few constraints here.
Alan Weiss
Alan Weiss 2019 年 3 月 26 日
If you are trying to minimize the sum of squares of the objective function values, then write the objective that way. See Nonlinear Data-Fitting.
Alan Weiss
MATLAB mathematical toolbox documentation

サインインしてコメントする。

Community Treasure Hunt

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

Start Hunting!

Translated by