How to convert interval from to scalar. The problem is:
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Indulis Straume
le 13 Sep 2021
Commenté : Walter Roberson
le 24 Sep 2021
k = -0.5:.05:-0.1; (interval)
prob.Objective = k * f1 * x(1) + f2 * x(2);
Result:
Objective must be a scalar OptimizationExpression or a struct containing a scalar OptimizationExpression.
0 commentaires
Réponse acceptée
Walter Roberson
le 13 Sep 2021
Modifié(e) : Walter Roberson
le 13 Sep 2021
You are trying to do multi-objective optimization, which is not supported by surrogate optimization or Problem Based Optimization
At that point in the code, whatever f1 and f2 are, they are effectively constants for the purpose of considering the values of k * f1 * x(1) + f2 * x(2) .
If f1*x(1) is positive, then the minimum of the combination k * f1 * x(1) + f2 * x(2) would always be at the point where k is most negative, and there is no point examining larger k.
If f1*x(1) is negative, then the minimum of the combination k * f1 * x(1) + f2 * x(2) would always be at the point where k is least negative, and there is no point examining smaller k.
Therefore, while there might be a point in evaluating at both k = -0.5 and k = -0.1, there is no point at evaluating the other members of the interval. And there is not even a point examining both of those k values:
temp = f1 * x(1);
if temp < 0
out = -0.1 * f1 * x(1) + f2 * x(2);
else
out = -0.5 * f1 * x(1) + f2 * x(2);
end
prob.Objective = out;
2 commentaires
Walter Roberson
le 24 Sep 2021
If f1*x(1) is positive, then the maximum of the combination k * f1 * x(1) + f2 * x(2) would always be at the point where k is most positive, and there is no point examining smaller k.
If f1*x(1) is negative, then the maximum of the combination k * f1 * x(1) + f2 * x(2) would always be at the point where k is least positive, and there is no point examining larger k.
Therefore, while there might be a point in evaluating at both k = -0.5 and k = -0.1, there is no point at evaluating the other members of the interval. And there is not even a point examining both of those k values:
temp = f1 * x(1);
if temp > 0
out = -0.1 * f1 * x(1) + f2 * x(2);
else
out = -0.5 * f1 * x(1) + f2 * x(2);
end
prob.Objective = out;
Plus de réponses (1)
Chunru
le 13 Sep 2021
Do you mean a loop over a number of interals?
k = -0.5:.05:-0.1; %(interval)
for i=1:length(k)
prob.Objective = k(i) * f1 * x(1) + f2 * x(2);
end
1 commentaire
Walter Roberson
le 13 Sep 2021
No, the user is trying to create an objective for Problem Based Optimization. Your code is overwriting the objective each time, and you cannot use
k = -0.5:.05:-0.1; %(interval)
for i=1:length(k)
prob.Objective(i) = k(i) * f1 * x(1) + f2 * x(2);
end
because problem-based optimization only permits a single scalar value for the Objective
Voir également
Catégories
En savoir plus sur Get Started with Optimization Toolbox dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!