Optimization Problem where Objective is not a direct function of Variable
Mostra commenti meno recenti
Hello !
I need to solve an optimization problem by minimizing the value of a variable B by iterating on the value of a variable x as follows:
prob = optimproblem;
x = optimvar('x','LowerBound',0,'UpperBound',100);
A = ComputeA (x);
B = ComputeB(A,x);
prob.Objective = B;
prob.Constraints.cons1 = B < ref;;
I can not manage to have this work. I have read through documentation but, in every example I came across, the problem Objective is a direct function of the optimvariable, wether linear or non-linear. In my case, I have to go through multiple calculations to go from x to B and so I can not get my prob.Objective to be a simple equation.
Has anyone ever coded something similar ?
Thank you in advance,
Regards.
1 Commento
Walter Roberson
il 21 Nov 2019
In some situations, if you have the symbolic toolbox, you can combine the equations by using something like
syms X
A = ComputeA(X);
B = ComputeB(A, X);
obj = matlabFunction(B, X);
and use solver-based optimization.
This will not work in all cases, and it is not uncommon that it needs a bit of tweaking of the code to make it work. For example, code such as
p = 0;
for K = 1 : 5; p = p + x.^p; end
might need to be change to instead use
p = zeros(1,1,'like', x);
Risposte (0)
Categorie
Scopri di più su Choose a Solver in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!