Azzera filtri
Azzera filtri

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 visualizzazioni (ultimi 30 giorni)
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

Risposta accettata

Matt J
Matt J il 8 Gen 2023
Modificato: Matt J il 8 Gen 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;

Più risposte (0)

Categorie

Scopri di più su Get Started with Optimization Toolbox in Help Center e File Exchange

Prodotti


Release

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by