<rss xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" version="2.0">
  <channel>
    <title>MaplePrimes - answers and comments on Question, LPSolve Matrix Form</title>
    <link>http://www.mapleprimes.com/questions/129179-LPSolve-Matrix-Form</link>
    <language>en-us</language>
    <copyright>2026 Maplesoft, A Division of Waterloo Maple Inc.</copyright>
    <generator>Maplesoft Document System</generator>
    <lastBuildDate>Sat, 13 Jun 2026 16:56:58 GMT</lastBuildDate>
    <pubDate>Sat, 13 Jun 2026 16:56:58 GMT</pubDate>
    <itunes:subtitle />
    <itunes:summary />
    <description>The latest answers and comments added to the Question, LPSolve Matrix Form</description>
    <image>
      <url>http://www.mapleprimes.com/images/mapleprimeswhite.jpg</url>
      <title>MaplePrimes - answers and comments on Question, LPSolve Matrix Form</title>
      <link>http://www.mapleprimes.com/questions/129179-LPSolve-Matrix-Form</link>
    </image>
    <item>
      <title>what's the problem?</title>
      <link>http://www.mapleprimes.com/questions/129179-LPSolve-Matrix-Form?ref=Feed:MaplePrimes:LPSolve Matrix Form:Comments#answer129191</link>
      <itunes:summary>&lt;p&gt;The notation of &lt;strong&gt;c'x&lt;/strong&gt; for the objective is just shorthand for a Vector dot product. It's a scalar, the result of the dot product of the row Vector &lt;strong&gt;c'&lt;/strong&gt; (ie. the transpose of column Vector &lt;strong&gt;c&lt;/strong&gt;) and the column Vector &lt;strong&gt;x&lt;/strong&gt;. The entries of Vector &lt;strong&gt;c&lt;/strong&gt; are the numeric coefficients, and the Vector &lt;strong&gt;x&lt;/strong&gt; are the as-yet-unknown variables. Hence &lt;strong&gt;c'x&lt;/strong&gt; is a linear combination -- not surprising as we are talking about &lt;strong&gt;L&lt;/strong&gt;inear &lt;strong&gt;P&lt;/strong&gt;rogramming problems.&lt;/p&gt;
&lt;p&gt;So,&amp;nbsp;in &lt;em&gt;Matrix form&lt;/em&gt;, the Vector &lt;strong&gt;x&lt;/strong&gt; for you example will have as it entries all the w[i] as well as dr and ur. But since for your example the objective &lt;strong&gt;c'x&lt;/strong&gt; is just the linear combination ur + dr = 0*w[1]+0*w[2]+...+0*w[50]+1.0*ur+1.0*dr then it is easy to see how to construct both &lt;strong&gt;c&lt;/strong&gt; and &lt;strong&gt;x&lt;/strong&gt; as Vectors.&lt;/p&gt;
&lt;p&gt;The Vector c might be taken as Vector(52,i-&amp;gt;`if`(i=51 or i=52, 1.0, 0.0))&lt;/p&gt;
&lt;p&gt;The Vector x would then be taken as Vector(52,i-&amp;gt;`if`(i=51,dr,`if`(i=52,ur,w[i])))&lt;/p&gt;
&lt;pre&gt;c:=Vector(52,i-&amp;gt;`if`(i=51 or i=52, 1.0, 0.0)):
x:=Vector(52,i-&amp;gt;`if`(i=51,dr,`if`(i=52,ur,w[i]))):

c^%T . x;
                        1.0 dr + 1.0 ur
&lt;/pre&gt;
&lt;p&gt;It is trivial to adjust, for a maximation problem.&lt;/p&gt;
&lt;p&gt;And now that you know what are the entries of the Vector &lt;strong&gt;x&lt;/strong&gt; of unknowns, you can see the &lt;a href="http://www.maplesoft.com/support/help/Maple/view.aspx?path=Optimization%2fLPSolveMatrixForm"&gt;LPSolve Matrix form&lt;/a&gt; help page for how to set up the linear constraints and simple bounds.&lt;/p&gt;
&lt;p&gt;If you are interested in efficiency, then use the syntax&amp;nbsp;&lt;strong&gt;z[i,1]&lt;/strong&gt; to access the entries of Matrix z, as the syntax &lt;strong&gt;z[i][1]&lt;/strong&gt; is quite an inefficient way to get the same thing. When you invoke z[i][1] you force Maple to waste resources extracting z[i]&amp;nbsp;(which is the i'th row of z)&amp;nbsp;as a new Vector object whose transient existence serves only to have its first entry extracted. But the syntax z[i,1] extracts the first entry in the i'th row directly, as a mere scalar. So, one way forms a new Vector (which takes resources to form as well as to collect and dispose of as garbage) just to extract a single scalar entry, while the other method simply extracts that same desired scalar entry directly with no such addtional overhead.&lt;/p&gt;</itunes:summary>
      <description>&lt;p&gt;The notation of &lt;strong&gt;c'x&lt;/strong&gt; for the objective is just shorthand for a Vector dot product. It's a scalar, the result of the dot product of the row Vector &lt;strong&gt;c'&lt;/strong&gt; (ie. the transpose of column Vector &lt;strong&gt;c&lt;/strong&gt;) and the column Vector &lt;strong&gt;x&lt;/strong&gt;. The entries of Vector &lt;strong&gt;c&lt;/strong&gt; are the numeric coefficients, and the Vector &lt;strong&gt;x&lt;/strong&gt; are the as-yet-unknown variables. Hence &lt;strong&gt;c'x&lt;/strong&gt; is a linear combination -- not surprising as we are talking about &lt;strong&gt;L&lt;/strong&gt;inear &lt;strong&gt;P&lt;/strong&gt;rogramming problems.&lt;/p&gt;
&lt;p&gt;So,&amp;nbsp;in &lt;em&gt;Matrix form&lt;/em&gt;, the Vector &lt;strong&gt;x&lt;/strong&gt; for you example will have as it entries all the w[i] as well as dr and ur. But since for your example the objective &lt;strong&gt;c'x&lt;/strong&gt; is just the linear combination ur + dr = 0*w[1]+0*w[2]+...+0*w[50]+1.0*ur+1.0*dr then it is easy to see how to construct both &lt;strong&gt;c&lt;/strong&gt; and &lt;strong&gt;x&lt;/strong&gt; as Vectors.&lt;/p&gt;
&lt;p&gt;The Vector c might be taken as Vector(52,i-&amp;gt;`if`(i=51 or i=52, 1.0, 0.0))&lt;/p&gt;
&lt;p&gt;The Vector x would then be taken as Vector(52,i-&amp;gt;`if`(i=51,dr,`if`(i=52,ur,w[i])))&lt;/p&gt;
&lt;pre&gt;c:=Vector(52,i-&amp;gt;`if`(i=51 or i=52, 1.0, 0.0)):
x:=Vector(52,i-&amp;gt;`if`(i=51,dr,`if`(i=52,ur,w[i]))):

c^%T . x;
                        1.0 dr + 1.0 ur
&lt;/pre&gt;
&lt;p&gt;It is trivial to adjust, for a maximation problem.&lt;/p&gt;
&lt;p&gt;And now that you know what are the entries of the Vector &lt;strong&gt;x&lt;/strong&gt; of unknowns, you can see the &lt;a href="http://www.maplesoft.com/support/help/Maple/view.aspx?path=Optimization%2fLPSolveMatrixForm"&gt;LPSolve Matrix form&lt;/a&gt; help page for how to set up the linear constraints and simple bounds.&lt;/p&gt;
&lt;p&gt;If you are interested in efficiency, then use the syntax&amp;nbsp;&lt;strong&gt;z[i,1]&lt;/strong&gt; to access the entries of Matrix z, as the syntax &lt;strong&gt;z[i][1]&lt;/strong&gt; is quite an inefficient way to get the same thing. When you invoke z[i][1] you force Maple to waste resources extracting z[i]&amp;nbsp;(which is the i'th row of z)&amp;nbsp;as a new Vector object whose transient existence serves only to have its first entry extracted. But the syntax z[i,1] extracts the first entry in the i'th row directly, as a mere scalar. So, one way forms a new Vector (which takes resources to form as well as to collect and dispose of as garbage) just to extract a single scalar entry, while the other method simply extracts that same desired scalar entry directly with no such addtional overhead.&lt;/p&gt;</description>
      <guid>129191</guid>
      <pubDate>Thu, 29 Dec 2011 11:18:36 Z</pubDate>
      <itunes:author>pagan</itunes:author>
      <author>pagan</author>
    </item>
    <item>
      <title>Ok, this is what I got so far. The first</title>
      <link>http://www.mapleprimes.com/questions/129179-LPSolve-Matrix-Form?ref=Feed:MaplePrimes:LPSolve Matrix Form:Comments#answer129199</link>
      <itunes:summary>&lt;p&gt;Ok, this is what I got so far. The first constraint is working (I think)&lt;br&gt;Constraint number 2 and 3 on the otherhand is not working. &lt;br&gt;&lt;br&gt;The second constraint gives an error message: cannot store ur in a floating-point r-table&lt;br&gt;The third constraint needs to be broken down in to many separate constrains I think&lt;br&gt;&lt;br&gt;restart: &lt;br&gt;randomize(): &lt;br&gt;with(Optimization): &lt;br&gt;with(Statistics): &lt;br&gt;with(LinearAlgebra): &lt;br&gt;&lt;br&gt;N := 12: &lt;br&gt;R := RandomMatrix(N, outputoptions = [datatype = float[8]]):&lt;br&gt;ER := Vector[column]([seq(ExpectedValue(Column(R, j)), j = 1 .. N)]):&lt;br&gt;&lt;br&gt;x := Vector(N+2, proc (i) options operator, arrow; `if`(i = 1, dr, `if`(i = 2, ur, w[i])) end proc):&lt;br&gt;c := Vector(N+2, proc (i) options operator, arrow; `if`(i = 1 or i = 2, 1.0, 0.) end proc):&lt;br&gt;&lt;br&gt;&lt;strong&gt;# 1) I think this constraint is ok&lt;/strong&gt;&lt;br&gt;Av := Matrix([[0, 0, seq(1, i = 1 .. N)]], datatype = float[8]): &lt;br&gt;bv := Vector([1], datatype = float[8]):&lt;br&gt;Av.x&amp;lt;bv;&lt;br&gt;&lt;br&gt;&lt;strong&gt;# 2) This constraint most likely not ok since I get an error message; &lt;/strong&gt;&lt;br&gt;&lt;strong&gt;# can not store ur in a floating-point r-table&lt;/strong&gt; &lt;br&gt;Az := Transpose(`&amp;lt;,&amp;gt;`(Matrix([0]), Matrix([0]), ER)): &lt;br&gt;bz := Vector([ur]):&lt;br&gt;Az.x&amp;lt;bz;&lt;br&gt;&lt;br&gt;&lt;strong&gt;# 3) This constraint is wrong as well. It becomes very difficult if you need to separate&lt;/strong&gt;&lt;br&gt;&lt;strong&gt;# it into many different constraints ie [ Aq[1],bq,Aq[2],bq,.....Aq[N+2,bq ]&lt;/strong&gt;&lt;br&gt;Aq := `&amp;lt;|&amp;gt;`(Vector([seq(0, i = 1 .. N+2)]), Vector([seq(0, i = 1 .. N+2)]), `&amp;lt;,&amp;gt;`(Matrix([seq(0, i = 1 .. N)]), Matrix([seq(0, i = 1 .. N)]), R)):&lt;br&gt;bq := Vector([0, 0, seq(dr, i = 1 .. 12)]):&lt;br&gt;Aq.x &amp;lt; bq ;&lt;/p&gt;</itunes:summary>
      <description>&lt;p&gt;Ok, this is what I got so far. The first constraint is working (I think)&lt;br&gt;Constraint number 2 and 3 on the otherhand is not working. &lt;br&gt;&lt;br&gt;The second constraint gives an error message: cannot store ur in a floating-point r-table&lt;br&gt;The third constraint needs to be broken down in to many separate constrains I think&lt;br&gt;&lt;br&gt;restart: &lt;br&gt;randomize(): &lt;br&gt;with(Optimization): &lt;br&gt;with(Statistics): &lt;br&gt;with(LinearAlgebra): &lt;br&gt;&lt;br&gt;N := 12: &lt;br&gt;R := RandomMatrix(N, outputoptions = [datatype = float[8]]):&lt;br&gt;ER := Vector[column]([seq(ExpectedValue(Column(R, j)), j = 1 .. N)]):&lt;br&gt;&lt;br&gt;x := Vector(N+2, proc (i) options operator, arrow; `if`(i = 1, dr, `if`(i = 2, ur, w[i])) end proc):&lt;br&gt;c := Vector(N+2, proc (i) options operator, arrow; `if`(i = 1 or i = 2, 1.0, 0.) end proc):&lt;br&gt;&lt;br&gt;&lt;strong&gt;# 1) I think this constraint is ok&lt;/strong&gt;&lt;br&gt;Av := Matrix([[0, 0, seq(1, i = 1 .. N)]], datatype = float[8]): &lt;br&gt;bv := Vector([1], datatype = float[8]):&lt;br&gt;Av.x&amp;lt;bv;&lt;br&gt;&lt;br&gt;&lt;strong&gt;# 2) This constraint most likely not ok since I get an error message; &lt;/strong&gt;&lt;br&gt;&lt;strong&gt;# can not store ur in a floating-point r-table&lt;/strong&gt; &lt;br&gt;Az := Transpose(`&amp;lt;,&amp;gt;`(Matrix([0]), Matrix([0]), ER)): &lt;br&gt;bz := Vector([ur]):&lt;br&gt;Az.x&amp;lt;bz;&lt;br&gt;&lt;br&gt;&lt;strong&gt;# 3) This constraint is wrong as well. It becomes very difficult if you need to separate&lt;/strong&gt;&lt;br&gt;&lt;strong&gt;# it into many different constraints ie [ Aq[1],bq,Aq[2],bq,.....Aq[N+2,bq ]&lt;/strong&gt;&lt;br&gt;Aq := `&amp;lt;|&amp;gt;`(Vector([seq(0, i = 1 .. N+2)]), Vector([seq(0, i = 1 .. N+2)]), `&amp;lt;,&amp;gt;`(Matrix([seq(0, i = 1 .. N)]), Matrix([seq(0, i = 1 .. N)]), R)):&lt;br&gt;bq := Vector([0, 0, seq(dr, i = 1 .. 12)]):&lt;br&gt;Aq.x &amp;lt; bq ;&lt;/p&gt;</description>
      <guid>129199</guid>
      <pubDate>Thu, 29 Dec 2011 18:11:47 Z</pubDate>
      <itunes:author>alex_01</itunes:author>
      <author>alex_01</author>
    </item>
    <item>
      <title>an example</title>
      <link>http://www.mapleprimes.com/questions/129179-LPSolve-Matrix-Form?ref=Feed:MaplePrimes:LPSolve Matrix Form:Comments#answer129362</link>
      <itunes:summary>&lt;p&gt;Here is a short example which might help you interpret and see the relationship between the algebraic and Matrix forms accepted by LPSolve.&lt;/p&gt;
&lt;p&gt;There is no exposed conversion utility (likely because one of the central purposes of the Matrix form is to never form the large expressions in the algebraic form at all). But you might experiment with the internal routine which I use below, in order to see what happens when there are no strict equality constraints, or no inequality constraints, or no simple variable bounds, and so on.&lt;/p&gt;
&lt;pre&gt;&amp;gt; restart:

&amp;gt; problem := -x-2*y, {7 &amp;gt;= 3*x+5*y, 113 &amp;gt;= -11*x-13*y, 17*x+19*y=23}, x=-29..31, y=-37..41:

&amp;gt; Optimization:-LPSolve(problem);

     [-2.92857142857143, [x = -0.642857142857142, y = 1.78571428571429]]

&amp;gt; kernelopts(opaquemodules=false):

&amp;gt; problem_matrix_form := Optimization:-Convert:-AlgebraicForm:-LPToMatrix(problem)[2..4];

        problem_matrix_form := [-1., -2.], 

          [[-11.  -13.]                               ]                            
          [[          ], [113., 7.], [17.  19.], [23.]], [[-29., -37.], [31., 41.]]
          [[  3.    5.]                               ]                            

&amp;gt; Optimization:-LPSolve(problem_matrix_form);

                  [                   [-0.642857142857142]]
                  [-2.92857142857143, [                  ]]
                  [                   [  1.78571428571429]]
&lt;/pre&gt;
&lt;p&gt;[edited] I might as well just do it. The first two places represent variables ur and dr, and the remaining N places represent w[i], i=1..N.&lt;/p&gt;
&lt;pre&gt;restart:
randomize():

with(Optimization):
with(Statistics):
with(LinearAlgebra):

N := 500:
R := RandomMatrix(N, outputoptions = [datatype = float[8]]):
ER := Vector[column]([seq(ExpectedValue(Column(R, j)), j = 1 .. N)]):

# algebraic form
st:=time():
W := Vector(N, symbol = w):
S := Vector(N, fill = 1, datatype = float[8]):
z := Multiply(R, Matrix(W)):
con1 := Transpose(W).S = 1:
con4 := seq(z[i][1] - dr &amp;gt;= 0, i = 1 .. N):
con5 := expand(Transpose(W).ER) - ur &amp;gt;= 0:
sol1:=LPSolve(ur+dr, {con1, con4, con5}, seq(w[i]=0..1,i=1..N), maximize = true):
sol1[1];
                        2.68825855741790
time()-st;
                             6.296

# Matrix form
st:=time():
A:=Matrix(N+1,N+2,datatype=float[8]):
A[2..-1,3..-1]:=R:
A[2..-1,1]:=Vector(N,fill=-1,datatype=float[8]):
A[1,3..-1]:=ER:
A[1,2]:=-1:
MatrixScalarMultiply(A,-1,inplace):
b:=Vector(N+1,datatype = float[8]):
#A,b;
Aeq:=Matrix(1,N+2,fill=1,datatype=float[8]):
Aeq[1,1..2]:=Vector(2,datatype=float[8]):
beq:=Vector(1,[1],datatype=float[8]):
#Aeq,beq;
c:=Vector(N+2,[1,1],datatype=float[8]):
#c;
bl:=Vector(N+2,datatype=float[8]):
bl[1..2]:=Vector(2,fill=-infinity):
bu:=Vector(N+2,fill=1,datatype=float[8]):
bu[1..2]:=Vector(2,fill=infinity,datatype=float[8]):
#bl,bu;
sol2:=Optimization:-LPSolve(c,[A,b,Aeq,beq],[bl,bu],maximize = true):
sol2[1];
                        2.68825855741790
time()-st;
                             3.735
&lt;/pre&gt;
&lt;!--break--&gt;
&lt;p&gt;So, half the time, for N=500. There are also memory savings on the order of the size of all the constraints as symbolic expressions, which I didn't bother to measure. There might be a relatively small bit more time saved, using ArrayTools routines like BlockCopy and Fill.&lt;/p&gt;
&lt;p&gt;acer&lt;/p&gt;</itunes:summary>
      <description>&lt;p&gt;Here is a short example which might help you interpret and see the relationship between the algebraic and Matrix forms accepted by LPSolve.&lt;/p&gt;
&lt;p&gt;There is no exposed conversion utility (likely because one of the central purposes of the Matrix form is to never form the large expressions in the algebraic form at all). But you might experiment with the internal routine which I use below, in order to see what happens when there are no strict equality constraints, or no inequality constraints, or no simple variable bounds, and so on.&lt;/p&gt;
&lt;pre&gt;&amp;gt; restart:

&amp;gt; problem := -x-2*y, {7 &amp;gt;= 3*x+5*y, 113 &amp;gt;= -11*x-13*y, 17*x+19*y=23}, x=-29..31, y=-37..41:

&amp;gt; Optimization:-LPSolve(problem);

     [-2.92857142857143, [x = -0.642857142857142, y = 1.78571428571429]]

&amp;gt; kernelopts(opaquemodules=false):

&amp;gt; problem_matrix_form := Optimization:-Convert:-AlgebraicForm:-LPToMatrix(problem)[2..4];

        problem_matrix_form := [-1., -2.], 

          [[-11.  -13.]                               ]                            
          [[          ], [113., 7.], [17.  19.], [23.]], [[-29., -37.], [31., 41.]]
          [[  3.    5.]                               ]                            

&amp;gt; Optimization:-LPSolve(problem_matrix_form);

                  [                   [-0.642857142857142]]
                  [-2.92857142857143, [                  ]]
                  [                   [  1.78571428571429]]
&lt;/pre&gt;
&lt;p&gt;[edited] I might as well just do it. The first two places represent variables ur and dr, and the remaining N places represent w[i], i=1..N.&lt;/p&gt;
&lt;pre&gt;restart:
randomize():

with(Optimization):
with(Statistics):
with(LinearAlgebra):

N := 500:
R := RandomMatrix(N, outputoptions = [datatype = float[8]]):
ER := Vector[column]([seq(ExpectedValue(Column(R, j)), j = 1 .. N)]):

# algebraic form
st:=time():
W := Vector(N, symbol = w):
S := Vector(N, fill = 1, datatype = float[8]):
z := Multiply(R, Matrix(W)):
con1 := Transpose(W).S = 1:
con4 := seq(z[i][1] - dr &amp;gt;= 0, i = 1 .. N):
con5 := expand(Transpose(W).ER) - ur &amp;gt;= 0:
sol1:=LPSolve(ur+dr, {con1, con4, con5}, seq(w[i]=0..1,i=1..N), maximize = true):
sol1[1];
                        2.68825855741790
time()-st;
                             6.296

# Matrix form
st:=time():
A:=Matrix(N+1,N+2,datatype=float[8]):
A[2..-1,3..-1]:=R:
A[2..-1,1]:=Vector(N,fill=-1,datatype=float[8]):
A[1,3..-1]:=ER:
A[1,2]:=-1:
MatrixScalarMultiply(A,-1,inplace):
b:=Vector(N+1,datatype = float[8]):
#A,b;
Aeq:=Matrix(1,N+2,fill=1,datatype=float[8]):
Aeq[1,1..2]:=Vector(2,datatype=float[8]):
beq:=Vector(1,[1],datatype=float[8]):
#Aeq,beq;
c:=Vector(N+2,[1,1],datatype=float[8]):
#c;
bl:=Vector(N+2,datatype=float[8]):
bl[1..2]:=Vector(2,fill=-infinity):
bu:=Vector(N+2,fill=1,datatype=float[8]):
bu[1..2]:=Vector(2,fill=infinity,datatype=float[8]):
#bl,bu;
sol2:=Optimization:-LPSolve(c,[A,b,Aeq,beq],[bl,bu],maximize = true):
sol2[1];
                        2.68825855741790
time()-st;
                             3.735
&lt;/pre&gt;
&lt;!--break--&gt;
&lt;p&gt;So, half the time, for N=500. There are also memory savings on the order of the size of all the constraints as symbolic expressions, which I didn't bother to measure. There might be a relatively small bit more time saved, using ArrayTools routines like BlockCopy and Fill.&lt;/p&gt;
&lt;p&gt;acer&lt;/p&gt;</description>
      <guid>129362</guid>
      <pubDate>Thu, 05 Jan 2012 22:33:11 Z</pubDate>
      <itunes:author>acer</itunes:author>
      <author>acer</author>
    </item>
    <item>
      <title>I am grateful for your loyal support.&amp;nbsp;</title>
      <link>http://www.mapleprimes.com/questions/129179-LPSolve-Matrix-Form?ref=Feed:MaplePrimes:LPSolve Matrix Form:Comments#comment129194</link>
      <itunes:summary>&lt;p&gt;I am grateful for your loyal support. I think that setting up a complex problem in &lt;br&gt;LP[Matrix Form] notation is extremly complicated. My brain really hurts. I just wish &lt;br&gt;that Maple did not separate between algebraic and matrix form ie if algebraic form &lt;br&gt;is entered then maple could convert it to matrix form and solve the problem &lt;br&gt;most efficiently. Now you have the option; Do you want to solve inefficiently&lt;br&gt;or efficiently? It does not really make any sense to give the user access to inefficiency.&lt;br&gt;Any how.......&lt;br&gt;&lt;br&gt;&lt;br&gt;This is as far as i got. I am having problems with the Aq,bq,Az,bz inequality constraints.&lt;br&gt;For Aq,bq I dont think I can reference z directly I have to do some transformation hummm&lt;br&gt;Also Aq.x&amp;gt;bq and Az.x&amp;gt;bz however by default Aq.x&amp;lt;bq and Az.x&amp;lt;bz, which is not what I&lt;br&gt;want. How can you get around that?&lt;br&gt;&lt;br&gt;It would be nice to be able to show that both LP[algebraic form] and LP[matrix form]&lt;br&gt;produces the same results....&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;restart: &lt;br&gt;randomize(): &lt;br&gt;with(Optimization): &lt;br&gt;with(Statistics): &lt;br&gt;with(LinearAlgebra): &lt;br&gt;&lt;br&gt;N := 12: &lt;br&gt;W := Vector(N, symbol = w): &lt;br&gt;R := RandomMatrix(N, outputoptions = [datatype = float[8]]): &lt;br&gt;ER := Vector[column]([seq(ExpectedValue(Column(R, j)), j = 1 .. N)]): &lt;br&gt;S := Vector(N, fill = 1, datatype = float[8]):&lt;br&gt;z := Multiply(R, Matrix(W)): &lt;br&gt;&lt;br&gt;con1 := Transpose(W).S = 1:&lt;br&gt;con2 := seq(w[i] &amp;gt;= 0, i = 1 .. N): &lt;br&gt;con3 := seq(w[i] &amp;lt;= 1, i = 1 .. N): &lt;br&gt;con4 := seq(z[i, 1] &amp;gt;= dr, i = 1 .. N): &lt;br&gt;con5 := expand(Transpose(W).ER) &amp;gt;= ur: &lt;br&gt;&lt;br&gt;LPSolve(ur+dr, {con1, con2, con3, con4, con5}, maximize = true); &lt;br&gt;&lt;br&gt;x := Vector(N+2, proc (i) options operator, arrow; `if`(i = 1, dr, `if`(i = 2, ur, w[i])) end proc):&lt;br&gt;c := Vector(N+2, proc (i) options operator, arrow; `if`(i = 1 or i = 2, 1.0, 0.) end proc):&lt;br&gt;&lt;br&gt;Av := Matrix([[0, 0, seq(1, i = 1 .. N)]], datatype = float[8]):&lt;br&gt;bv := Vector([1], datatype = float[8]):&lt;br&gt;&lt;br&gt;# problem constraints (linear inequality constraints)&lt;br&gt;Aq := Matrix([[0, 0, seq(z[i, 1], i = 1 .. N)]]): &lt;br&gt;bq := Vector([dr]):&lt;br&gt;Az := Matrix([[0, 0, seq(z[i, 1], i = 1 .. N)]]):&lt;br&gt;bz := Vector([ur]):&lt;br&gt;&lt;br&gt;bl := Vector(N+2, proc (i) options operator, arrow; `if`(i = 1, -20, `if`(i = 2, -20, 0.)) end proc):&lt;br&gt;bu := Vector(N+2, proc (i) options operator, arrow; `if`(i = 1, 20, `if`(i = 2, 20, 1.0)) end proc): &lt;br&gt;&lt;br&gt;LPSolve(c, [Av, bv, Aq, bq, Az, bz], [bl, bu], maximize = true);&lt;/p&gt;</itunes:summary>
      <description>&lt;p&gt;I am grateful for your loyal support. I think that setting up a complex problem in &lt;br&gt;LP[Matrix Form] notation is extremly complicated. My brain really hurts. I just wish &lt;br&gt;that Maple did not separate between algebraic and matrix form ie if algebraic form &lt;br&gt;is entered then maple could convert it to matrix form and solve the problem &lt;br&gt;most efficiently. Now you have the option; Do you want to solve inefficiently&lt;br&gt;or efficiently? It does not really make any sense to give the user access to inefficiency.&lt;br&gt;Any how.......&lt;br&gt;&lt;br&gt;&lt;br&gt;This is as far as i got. I am having problems with the Aq,bq,Az,bz inequality constraints.&lt;br&gt;For Aq,bq I dont think I can reference z directly I have to do some transformation hummm&lt;br&gt;Also Aq.x&amp;gt;bq and Az.x&amp;gt;bz however by default Aq.x&amp;lt;bq and Az.x&amp;lt;bz, which is not what I&lt;br&gt;want. How can you get around that?&lt;br&gt;&lt;br&gt;It would be nice to be able to show that both LP[algebraic form] and LP[matrix form]&lt;br&gt;produces the same results....&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;restart: &lt;br&gt;randomize(): &lt;br&gt;with(Optimization): &lt;br&gt;with(Statistics): &lt;br&gt;with(LinearAlgebra): &lt;br&gt;&lt;br&gt;N := 12: &lt;br&gt;W := Vector(N, symbol = w): &lt;br&gt;R := RandomMatrix(N, outputoptions = [datatype = float[8]]): &lt;br&gt;ER := Vector[column]([seq(ExpectedValue(Column(R, j)), j = 1 .. N)]): &lt;br&gt;S := Vector(N, fill = 1, datatype = float[8]):&lt;br&gt;z := Multiply(R, Matrix(W)): &lt;br&gt;&lt;br&gt;con1 := Transpose(W).S = 1:&lt;br&gt;con2 := seq(w[i] &amp;gt;= 0, i = 1 .. N): &lt;br&gt;con3 := seq(w[i] &amp;lt;= 1, i = 1 .. N): &lt;br&gt;con4 := seq(z[i, 1] &amp;gt;= dr, i = 1 .. N): &lt;br&gt;con5 := expand(Transpose(W).ER) &amp;gt;= ur: &lt;br&gt;&lt;br&gt;LPSolve(ur+dr, {con1, con2, con3, con4, con5}, maximize = true); &lt;br&gt;&lt;br&gt;x := Vector(N+2, proc (i) options operator, arrow; `if`(i = 1, dr, `if`(i = 2, ur, w[i])) end proc):&lt;br&gt;c := Vector(N+2, proc (i) options operator, arrow; `if`(i = 1 or i = 2, 1.0, 0.) end proc):&lt;br&gt;&lt;br&gt;Av := Matrix([[0, 0, seq(1, i = 1 .. N)]], datatype = float[8]):&lt;br&gt;bv := Vector([1], datatype = float[8]):&lt;br&gt;&lt;br&gt;# problem constraints (linear inequality constraints)&lt;br&gt;Aq := Matrix([[0, 0, seq(z[i, 1], i = 1 .. N)]]): &lt;br&gt;bq := Vector([dr]):&lt;br&gt;Az := Matrix([[0, 0, seq(z[i, 1], i = 1 .. N)]]):&lt;br&gt;bz := Vector([ur]):&lt;br&gt;&lt;br&gt;bl := Vector(N+2, proc (i) options operator, arrow; `if`(i = 1, -20, `if`(i = 2, -20, 0.)) end proc):&lt;br&gt;bu := Vector(N+2, proc (i) options operator, arrow; `if`(i = 1, 20, `if`(i = 2, 20, 1.0)) end proc): &lt;br&gt;&lt;br&gt;LPSolve(c, [Av, bv, Aq, bq, Az, bz], [bl, bu], maximize = true);&lt;/p&gt;</description>
      <guid>129194</guid>
      <pubDate>Thu, 29 Dec 2011 14:09:49 Z</pubDate>
      <itunes:author>alex_01</itunes:author>
      <author>alex_01</author>
    </item>
    <item>
      <title>a matter of the set up, not the solving</title>
      <link>http://www.mapleprimes.com/questions/129179-LPSolve-Matrix-Form?ref=Feed:MaplePrimes:LPSolve Matrix Form:Comments#comment129202</link>
      <itunes:summary>&lt;p&gt;&lt;a href="http://www.mapleprimes.com/questions/129179-LPSolve-Matrix-Form#comment129194"&gt;@alex_01&lt;/a&gt;&amp;nbsp;The whole efficiency question for Matrix-form vs algebraic-form has to do with the problem setup, not with the actual solving stage.&lt;/p&gt;
&lt;p&gt;The Optimization routine converts the algebraic form into Matrix form, before passing it externally to the compiled solver. The external, compiled solver only knows how to work with the Matrix form which is comprised purely of collections of floating-point numbers.&lt;/p&gt;
&lt;p&gt;The inefficiency is thus in the forming of the algebraic form, in the storing of the algebraic form entities in Maple (takes more memory than does the Matrix form), and in the decomposing of the algebraic form into the Matrix form.&lt;/p&gt;
&lt;p&gt;If you can formulate the problem directly in Matrix form, then you have saved resources. If, however, you form it in algebraic form, only to then manually convert it to Matrix form yourself, then you have saved nothing over what Optimization itself would do internally.&lt;/p&gt;
&lt;p&gt;Perhaps your problems will not be huge enough for all this to matter so much?&lt;/p&gt;
&lt;p&gt;Good luck, and a Happy New Year to you and yours!&lt;/p&gt;</itunes:summary>
      <description>&lt;p&gt;&lt;a href="http://www.mapleprimes.com/questions/129179-LPSolve-Matrix-Form#comment129194"&gt;@alex_01&lt;/a&gt;&amp;nbsp;The whole efficiency question for Matrix-form vs algebraic-form has to do with the problem setup, not with the actual solving stage.&lt;/p&gt;
&lt;p&gt;The Optimization routine converts the algebraic form into Matrix form, before passing it externally to the compiled solver. The external, compiled solver only knows how to work with the Matrix form which is comprised purely of collections of floating-point numbers.&lt;/p&gt;
&lt;p&gt;The inefficiency is thus in the forming of the algebraic form, in the storing of the algebraic form entities in Maple (takes more memory than does the Matrix form), and in the decomposing of the algebraic form into the Matrix form.&lt;/p&gt;
&lt;p&gt;If you can formulate the problem directly in Matrix form, then you have saved resources. If, however, you form it in algebraic form, only to then manually convert it to Matrix form yourself, then you have saved nothing over what Optimization itself would do internally.&lt;/p&gt;
&lt;p&gt;Perhaps your problems will not be huge enough for all this to matter so much?&lt;/p&gt;
&lt;p&gt;Good luck, and a Happy New Year to you and yours!&lt;/p&gt;</description>
      <guid>129202</guid>
      <pubDate>Thu, 29 Dec 2011 20:02:11 Z</pubDate>
      <itunes:author>pagan</itunes:author>
      <author>pagan</author>
    </item>
    <item>
      <title>hummm</title>
      <link>http://www.mapleprimes.com/questions/129179-LPSolve-Matrix-Form?ref=Feed:MaplePrimes:LPSolve Matrix Form:Comments#comment129205</link>
      <itunes:summary>&lt;p&gt;&lt;a href="http://www.mapleprimes.com/questions/129179-LPSolve-Matrix-Form#comment129202"&gt;@pagan&lt;/a&gt; If Maple automatically convert the problem into LP[matrix form] why cant &lt;br&gt;Maple show me the output of such matrix form conversion? &lt;br&gt;&lt;br&gt;Then I could i) specify the LP in the usuall manner ii) have maple convert it&lt;br&gt;to matrix form iii) look at the output from such convertion&amp;nbsp; iiii) respecify the&lt;br&gt;problem as iii)&lt;br&gt;&lt;br&gt;That would save a lot of headache. I know Maple has functions like &lt;br&gt;GenerateMatrix() but it is still difficult.&lt;br&gt;&lt;br&gt;My main problem now is that Maple cant store dr and ur in floating point r-tables&lt;br&gt;hence I doubt that my problem can be solved even though if I specify it in the&lt;br&gt;usuall manner Maple manage to convert it to matrix form hence it should be &lt;br&gt;doable. I am confused.....&lt;br&gt;&lt;br&gt;PS Speed is critical in this calculation, hence matrix form LP is important.&lt;/p&gt;</itunes:summary>
      <description>&lt;p&gt;&lt;a href="http://www.mapleprimes.com/questions/129179-LPSolve-Matrix-Form#comment129202"&gt;@pagan&lt;/a&gt; If Maple automatically convert the problem into LP[matrix form] why cant &lt;br&gt;Maple show me the output of such matrix form conversion? &lt;br&gt;&lt;br&gt;Then I could i) specify the LP in the usuall manner ii) have maple convert it&lt;br&gt;to matrix form iii) look at the output from such convertion&amp;nbsp; iiii) respecify the&lt;br&gt;problem as iii)&lt;br&gt;&lt;br&gt;That would save a lot of headache. I know Maple has functions like &lt;br&gt;GenerateMatrix() but it is still difficult.&lt;br&gt;&lt;br&gt;My main problem now is that Maple cant store dr and ur in floating point r-tables&lt;br&gt;hence I doubt that my problem can be solved even though if I specify it in the&lt;br&gt;usuall manner Maple manage to convert it to matrix form hence it should be &lt;br&gt;doable. I am confused.....&lt;br&gt;&lt;br&gt;PS Speed is critical in this calculation, hence matrix form LP is important.&lt;/p&gt;</description>
      <guid>129205</guid>
      <pubDate>Thu, 29 Dec 2011 20:41:26 Z</pubDate>
      <itunes:author>alex_01</itunes:author>
      <author>alex_01</author>
    </item>
  </channel>
</rss>