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