Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

Error using optimization tool bx

조회 수: 1 (최근 30일)
Jay Loh
Jay Loh 2020년 2월 16일
마감: MATLAB Answer Bot 2021년 8월 20일
I created a sciprt file name objective
And i key in the function below
function f = objective(x)
f = -2.84.*x(:,1)+0.22.*x(:,2)+3.33.*x(:,3)-1.09.*x(:,4)-9.39.*x(:,5)-9.51.*x(:,6)+0;
A:[1.1 0.9 0.9 1 1.1 0.9; 0.5 0.35 0.25 0.25 0.5 0.35; 0.01 0.15 0.15 0.18 0.01 0.15 ]
B: [200000 100000 20000]
Aeq: [0.4 0.06 0.04 0.05 -0.6 0.06; 0 0.1 0.01 0.01 0 -0.9; -6857.6 364 2032 -1145 -6857.6 364 21520]
Beq:[0 0 20000000]
When solve by optimum toolbox it displays message below:
Optimization running.
Error running optimization.
LINPROG requires the following inputs to be of data type double: 'f'.
  댓글 수: 2
Gifari Zulkarnaen
Gifari Zulkarnaen 2020년 2월 16일
What is difference between A and B equality? They should be in one equation, unless one of them is inequality.
Walter Roberson
Walter Roberson 2020년 2월 16일
In standard constraint notation used by MATLAB,
A*X <= B
Aeq*X == Beq
That is, A and B express an inequality, and Aeq and Beq express an equality.

답변 (2개)

Gifari Zulkarnaen
Gifari Zulkarnaen 2020년 2월 16일
Try this
[x,fval] = ga(@objective,6);
function f = objective(x)
f = -2.84.*x(:,1)+0.22.*x(:,2)+3.33.*x(:,3)-1.09.*x(:,4)-9.39.*x(:,5)-9.51.*x(:,6)+0;
end
  댓글 수: 6
Walter Roberson
Walter Roberson 2020년 2월 16일
When you have a function in a file and the first executable word of the file is not "function" then the function name cannot be the same as the file name.
Walter Roberson
Walter Roberson 2020년 2월 16일
Is your requirement to define a script that minimizes a certain linear system and the script must be named objective ? If so then name the script objective.m but rename the function inside it to something else.
Is your requirement to define a function named objective that is to be used in minimizing a nonlinear system, together with a script that invokes the appropriate minimizer? If so then put the function in its own file named objective.m and put the driving script into a different file.

Walter Roberson
Walter Roberson 2020년 2월 16일
linprog() does not permit a function handle as the first argument. linprog is linear programming, which permits the problem to be described by numeric matrices. Function handles are not permitted because function handles usually imply nonlinear functions.

이 질문은 마감되었습니다.

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by