Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I tried to run a large scale linear programming with mathematica. I entered the code below:

Import["A,B.mat", "LabeledData"]
x = LinearProgramming[{0, 0, -1}, A, B, {{-1, 100}, {0, 100}, {0, 100}}];
c.x

where A, B are two large scale matrices. {{-1, 100}, {0, 100}, {0, 100}} are bounds of variabels of linear programming. The code doesn't work and I think there is sth wrong with importing matrices A and B. How can I fix that?

Edit: Data file access from here

share|improve this question
2  
Please provide the data file so we can see for ourselves. –  Mr.Wizard Jan 28 at 9:43
    
@Mr.Wizard Sorry. How can I add it to post? It is a .mat file (344 KB) –  user2667048 Jan 28 at 11:54
    
You will need to upload it somewhere accessible. I'm sorry, but StackExchange does not provide that service. Nevertheless without the data I feel that this question is impossible to answer. –  Mr.Wizard Jan 28 at 12:12
1  
@Mr.Wizard data file added. –  user2667048 Jan 28 at 12:19
1  
@user2667048 you can try imp = Import["A.mat", "LabeledData"]; AA = "A" /. imp ; BB = "B" /. imp ; x = LinearProgramming[{0, 0, -1}, AA, Flatten@BB, {{-1, 100}, {0, 100}, {0, 100}}]; –  s.s.o Jan 28 at 12:47
show 2 more comments

1 Answer

up vote 6 down vote accepted

If you carefully check what has been imported, you'll see that it imports matrix labels and the values.

imp = Import["A.mat", "LabeledData"];

{"A" -> {{-1.13043, 1., 1.50927}, {-1.13043, 1., 1.50927},...

(*Get A and B matrix values*)
AA = "A" /. imp ; 
BB = "B" /. imp ; 

And flatten BB so that it becomes a vector.

x = LinearProgramming[{0, 0, -1}, AA, Flatten@BB,
      {{-1, 100}, {0, 100}, {0, 100}}];
c x
share|improve this answer
2  
That's work. It's amazing that definition of inequality constrained in Mathematica and MATLAB are not the same. (I can't vote up! Thanks +1) –  user2667048 Jan 28 at 15:00
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.