How to convert interval from to scalar. The problem is:

6 Ansichten (letzte 30 Tage)
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.

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 13 Sep. 2021
Bearbeitet: Walter Roberson am 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 Kommentare
Indulis Straume
Indulis Straume am 13 Sep. 2021
but if k * f1 * x(1) + f2 * x(2) need a maximum?
The value of K must then be the least negative?
Walter Roberson
Walter Roberson am 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;

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Chunru
Chunru am 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 Kommentar
Walter Roberson
Walter Roberson am 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

Melden Sie sich an, um zu kommentieren.

Kategorien

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

Produkte


Version

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by