Problems with fmincon constraints writing
Ältere Kommentare anzeigen
Hi all,
i am writing code to optimize my onstraint in given equation.

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
Antworten (1)
Alan Weiss
am 26 Mär. 2019
0 Stimmen
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 Kommentare
Saurabh Gupta
am 26 Mär. 2019
Alan Weiss
am 26 Mär. 2019
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
Kategorien
Mehr zu Choose a Solver finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!