Error using optimization tool bx

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 Comments

What is difference between A and B equality? They should be in one equation, unless one of them is inequality.
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.

Answers (2)

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 Comments

still cannot solve it
It works in my matlab. Can you describe how it cannot in yours?
Bcs i need to create a script file name objective
I key in the base on what your teach
it shows unable to define location function 'objective' bcs it has a same name as the file
How about changing either the file name or the function name?
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.
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 on 16 Feb 2020
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.

This question is closed.

Products

Tags

Asked:

on 16 Feb 2020

Closed:

on 20 Aug 2021

Community Treasure Hunt

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

Start Hunting!