Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Error: bintprog only accepts inputs of data type double

Subject: Error: bintprog only accepts inputs of data type double

From: Greg

Date: 11 Jun, 2013 03:36:08

Message: 1 of 3

Probably a simple mistake I'm just not seeing right now, but for some reason I don't understand why I'm getting this error.
"bintprog only accepts inputs of data type double"

My program:

% Minimize f(X)
% F(X) = -x1-x2-x3-x4-x5-x6-x7-x8-x9-x10-x11-x12-x13-x14-x15-x16
% g1(X): Sum of all elements in each row must be even
% g2(X): sum of all elements in each column must be even
% g3(X): sum of all elements in each diagonal must be even
% Calls the functions Puzzle_fun containting the function to be minimized
% and Puzzle_con containing the constraints of the function
x0=[0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0];
x=bintprog(@Puzzle_fun,[],[],@Puzzle_con,x0)

function f = Puzzle_fun(x)
f = -x(1)-x(2)-x(3)-x(4)-x(5)-x(6)-x(7)-x(8)-x(9)-x(10)-x(11)-x(12)-x(13)-x(14)-x(15)-x(16);

function [Aeq,beq] = Puzzle_con(x)
% Row Constraints: Sum must be even
Aeq(1) = x(1)+x(2)+x(3)+x(4)-2*(x(19)+x(20));
Aeq(2) = x(5)+x(6)+x(7)+x(8)-2*(x(21)+x(22));
Aeq(3) = x(9)+x(10)+x(11)+x(12)-2*(x(23)+x(24));
Aeq(4) = x(13)+x(14)+x(15)+x(16)-2*(x(25)+x(26));
% Column Constraints: Sum must be even
Aeq(5) = x(1)+x(5)+x(9)+x(13)-2*(x(27)+x(29));
Aeq(6) = x(2)+x(6)+x(10)+x(14)-2*(x(30)+x(31));
Aeq(7) = x(3)+x(7)+x(11)+x(15)-2*(x(32)+x(33));
Aeq(8) = x(4)+x(8)+x(12)+x(16)-2*(x(34)+x(35));
% Diagonal Constraints: Sum must be even
Aeq(9) = x(2)+x(5)-2*x(36);
Aeq(10)= x(3)+x(6)+x(9)-2*x(37);
Aeq(11)= x(4)+x(7)+x(10)+x(13)-2*(x(38)+x(39));
Aeq(12)= x(8)+x(11)+x(14)-2*x(40);
Aeq(13)= x(12)+x(15)-2*x(41);
Aeq(14)= x(3)+x(8)-2*x(42);
Aeq(15)= x(2)+x(7)+x(12)-2*x(43);
Aeq(16)= x(1)+x(6)+x(11)+x(16)-2*(x(44)+x(45));
Aeq(17)= x(5)+x(10)+x(15)-2*x(46);
Aeq(18)= x(9)+x(14)-2*x(48);

% All constraints are set up as 'equal to zero'
beq(1)=0;
beq(2)=0;
beq(3)=0;
beq(4)=0;
beq(5)=0;
beq(6)=0;
beq(7)=0;
beq(8)=0;
beq(9)=0;
beq(10)=0;
beq(11)=0;
beq(12)=0;
beq(13)=0;
beq(14)=0;
beq(15)=0;
beq(16)=0;
beq(17)=0;
beq(18)=0;

Subject: Error: bintprog only accepts inputs of data type double

From: Torsten

Date: 11 Jun, 2013 08:00:29

Message: 2 of 3

"Greg" wrote in message <kp65v8$dr8$1@newscl01ah.mathworks.com>...
> Probably a simple mistake I'm just not seeing right now, but for some reason I don't understand why I'm getting this error.
> "bintprog only accepts inputs of data type double"
>
> My program:
>
> % Minimize f(X)
> % F(X) = -x1-x2-x3-x4-x5-x6-x7-x8-x9-x10-x11-x12-x13-x14-x15-x16
> % g1(X): Sum of all elements in each row must be even
> % g2(X): sum of all elements in each column must be even
> % g3(X): sum of all elements in each diagonal must be even
> % Calls the functions Puzzle_fun containting the function to be minimized
> % and Puzzle_con containing the constraints of the function
> x0=[0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0];
> x=bintprog(@Puzzle_fun,[],[],@Puzzle_con,x0)
>
> function f = Puzzle_fun(x)
> f = -x(1)-x(2)-x(3)-x(4)-x(5)-x(6)-x(7)-x(8)-x(9)-x(10)-x(11)-x(12)-x(13)-x(14)-x(15)-x(16);
>
> function [Aeq,beq] = Puzzle_con(x)
> % Row Constraints: Sum must be even
> Aeq(1) = x(1)+x(2)+x(3)+x(4)-2*(x(19)+x(20));
> Aeq(2) = x(5)+x(6)+x(7)+x(8)-2*(x(21)+x(22));
> Aeq(3) = x(9)+x(10)+x(11)+x(12)-2*(x(23)+x(24));
> Aeq(4) = x(13)+x(14)+x(15)+x(16)-2*(x(25)+x(26));
> % Column Constraints: Sum must be even
> Aeq(5) = x(1)+x(5)+x(9)+x(13)-2*(x(27)+x(29));
> Aeq(6) = x(2)+x(6)+x(10)+x(14)-2*(x(30)+x(31));
> Aeq(7) = x(3)+x(7)+x(11)+x(15)-2*(x(32)+x(33));
> Aeq(8) = x(4)+x(8)+x(12)+x(16)-2*(x(34)+x(35));
> % Diagonal Constraints: Sum must be even
> Aeq(9) = x(2)+x(5)-2*x(36);
> Aeq(10)= x(3)+x(6)+x(9)-2*x(37);
> Aeq(11)= x(4)+x(7)+x(10)+x(13)-2*(x(38)+x(39));
> Aeq(12)= x(8)+x(11)+x(14)-2*x(40);
> Aeq(13)= x(12)+x(15)-2*x(41);
> Aeq(14)= x(3)+x(8)-2*x(42);
> Aeq(15)= x(2)+x(7)+x(12)-2*x(43);
> Aeq(16)= x(1)+x(6)+x(11)+x(16)-2*(x(44)+x(45));
> Aeq(17)= x(5)+x(10)+x(15)-2*x(46);
> Aeq(18)= x(9)+x(14)-2*x(48);
>
> % All constraints are set up as 'equal to zero'
> beq(1)=0;
> beq(2)=0;
> beq(3)=0;
> beq(4)=0;
> beq(5)=0;
> beq(6)=0;
> beq(7)=0;
> beq(8)=0;
> beq(9)=0;
> beq(10)=0;
> beq(11)=0;
> beq(12)=0;
> beq(13)=0;
> beq(14)=0;
> beq(15)=0;
> beq(16)=0;
> beq(17)=0;
> beq(18)=0;

Never seen that you can specify f, Aeq and beq the way you do above.
At least for Aeq, it's wrong since you have to specify Aeq, not Aeq*x.
Take a look at
http://www.mathworks.de/de/help/optim/ug/bintprog.html#f768700
on how the inputs to binprog are usually prescribed.

Best wishes
Torsten.

Subject: Error: bintprog only accepts inputs of data type double

From: Johan Lofberg

Date: 11 Jun, 2013 09:42:11

Message: 3 of 3

"Greg" wrote in message <kp65v8$dr8$1@newscl01ah.mathworks.com>...
> Probably a simple mistake I'm just not seeing right now, but for some reason I don't understand why I'm getting this error.
> "bintprog only accepts inputs of data type double"
>
> My program:
>
> % Minimize f(X)
> % F(X) = -x1-x2-x3-x4-x5-x6-x7-x8-x9-x10-x11-x12-x13-x14-x15-x16
> % g1(X): Sum of all elements in each row must be even
> % g2(X): sum of all elements in each column must be even
> % g3(X): sum of all elements in each diagonal must be even
> % Calls the functions Puzzle_fun containting the function to be minimized
> % and Puzzle_con containing the constraints of the function
> x0=[0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0];
> x=bintprog(@Puzzle_fun,[],[],@Puzzle_con,x0)
>
> function f = Puzzle_fun(x)
> f = -x(1)-x(2)-x(3)-x(4)-x(5)-x(6)-x(7)-x(8)-x(9)-x(10)-x(11)-x(12)-x(13)-x(14)-x(15)-x(16);
>
> function [Aeq,beq] = Puzzle_con(x)
> % Row Constraints: Sum must be even
> Aeq(1) = x(1)+x(2)+x(3)+x(4)-2*(x(19)+x(20));
> Aeq(2) = x(5)+x(6)+x(7)+x(8)-2*(x(21)+x(22));
> Aeq(3) = x(9)+x(10)+x(11)+x(12)-2*(x(23)+x(24));
> Aeq(4) = x(13)+x(14)+x(15)+x(16)-2*(x(25)+x(26));
> % Column Constraints: Sum must be even
> Aeq(5) = x(1)+x(5)+x(9)+x(13)-2*(x(27)+x(29));
> Aeq(6) = x(2)+x(6)+x(10)+x(14)-2*(x(30)+x(31));
> Aeq(7) = x(3)+x(7)+x(11)+x(15)-2*(x(32)+x(33));
> Aeq(8) = x(4)+x(8)+x(12)+x(16)-2*(x(34)+x(35));
> % Diagonal Constraints: Sum must be even
> Aeq(9) = x(2)+x(5)-2*x(36);
> Aeq(10)= x(3)+x(6)+x(9)-2*x(37);
> Aeq(11)= x(4)+x(7)+x(10)+x(13)-2*(x(38)+x(39));
> Aeq(12)= x(8)+x(11)+x(14)-2*x(40);
> Aeq(13)= x(12)+x(15)-2*x(41);
> Aeq(14)= x(3)+x(8)-2*x(42);
> Aeq(15)= x(2)+x(7)+x(12)-2*x(43);
> Aeq(16)= x(1)+x(6)+x(11)+x(16)-2*(x(44)+x(45));
> Aeq(17)= x(5)+x(10)+x(15)-2*x(46);
> Aeq(18)= x(9)+x(14)-2*x(48);
>
> % All constraints are set up as 'equal to zero'
> beq(1)=0;
> beq(2)=0;
> beq(3)=0;
> beq(4)=0;
> beq(5)=0;
> beq(6)=0;
> beq(7)=0;
> beq(8)=0;
> beq(9)=0;
> beq(10)=0;
> beq(11)=0;
> beq(12)=0;
> beq(13)=0;
> beq(14)=0;
> beq(15)=0;
> beq(16)=0;
> beq(17)=0;
> beq(18)=0;

bintprog does not use function handles as you try to do. Everything is matrices and vectors
  min f'*x subject to: A*x <= b,
                               B*x = c,

The first argument should be a vector of costs
f = zeros(48,1);
f(1:16) = -1;

A = [];
b = [];

B would be something like
B = zeros(18,48);
B([1 2 3 4 19 20]) = [1 1 1 1 -2 -2];
etc...
c = zeros(18,1);

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us