Filter löschen
Filter löschen

How to optimize a system with 5 optimization variables, 4 of them are in the objective function and the 5th is in the constriants?

3 Ansichten (letzte 30 Tage)
Let's assume that we need to optimize a function f with 5 optimization variables (V,W,X,Y,Z)
the fitness function it self includes 4 variables i.e. f= V*W*X*Y
and the 5th variable Z is in the constraints i.e constraint1 = 5*V - Z =0; constraint2 = 5*W - Z =0;
do i include the variable Z in the fitness function to be function f = objFcn(V,W,X,Y,Z) and there is no stetments of Z in the fitness function, or do i put it in the constraints function i,e.
n = constraints(V,W,Z) and put the two constraints and it will give me no enough input arguments

Akzeptierte Antwort

Matt J
Matt J am 8 Jan. 2023
Bearbeitet: Matt J am 8 Jan. 2023
If you are using the Solver-Based framework, you must pass all the unknowns both to the objective and constraints as a vector p=[V,W,X,Y,Z]. The optimation solvers do not know or care which variables are actually used in either place. So, it will not be f = objFcn(V,W,X,Y,Z), but rather f=objFcn(p). Additonally, when you have linear equality constraints, as in your case, you will express them using matrix multiplication Aeq*p=beq, where Aeq is a 5-column matrix,
Aeq=[5,0,0,0,-1;
0,5,0,0,-1 ]
beq=[0;0]
If you are using the Problem-Based framework, then you are free to separate them, although this is not required,
V=optimvar('V',___);
W=optimvar('W',___);
X=optimvar('X',___);
Y=optimvar('Y',___);
Z=optimvar('Z',___);
f=fcn2optimexpr( @objFcn, V,W,X,Y);
Con.constraint1 = 5*V - Z =0;
Con.constraint2 = 5*W - Z =0;

Weitere Antworten (0)

Kategorien

Mehr zu Get Started with Optimization Toolbox finden Sie in Help Center und File Exchange

Produkte


Version

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by