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

조회 수: 6 (최근 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 CenterFile Exchange에서 Get 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