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

9 ビュー (過去 30 日間)
Indulis Straume
Indulis Straume 2021 年 9 月 13 日
コメント済み: Walter Roberson 2021 年 9 月 24 日
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.

採用された回答

Walter Roberson
Walter Roberson 2021 年 9 月 13 日
編集済み: Walter Roberson 2021 年 9 月 13 日
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 件のコメント
Indulis Straume
Indulis Straume 2021 年 9 月 13 日
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 2021 年 9 月 24 日
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;

サインインしてコメントする。

その他の回答 (1 件)

Chunru
Chunru 2021 年 9 月 13 日
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 件のコメント
Walter Roberson
Walter Roberson 2021 年 9 月 13 日
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

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeGet Started with Optimization Toolbox についてさらに検索

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by