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