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

7 visualizaciones (últimos 30 días)
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.

Respuesta aceptada

Walter Roberson
Walter Roberson el 13 de Sept. de 2021
Editada: Walter Roberson el 13 de Sept. de 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 comentarios
Indulis Straume
Indulis Straume el 13 de Sept. de 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 el 24 de Sept. de 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;

Iniciar sesión para comentar.

Más respuestas (1)

Chunru
Chunru el 13 de Sept. de 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 comentario
Walter Roberson
Walter Roberson el 13 de Sept. de 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

Iniciar sesión para comentar.

Categorías

Más información sobre Get Started with Optimization Toolbox en Help Center y File Exchange.

Productos


Versión

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by