<rss xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" version="2.0">
  <channel>
    <title>MaplePrimes - answers and comments on Question, NLPSolve Matrix Form</title>
    <link>http://www.mapleprimes.com/questions/129419-NLPSolve-Matrix-Form</link>
    <language>en-us</language>
    <copyright>2026 Maplesoft, A Division of Waterloo Maple Inc.</copyright>
    <generator>Maplesoft Document System</generator>
    <lastBuildDate>Thu, 11 Jun 2026 20:34:22 GMT</lastBuildDate>
    <pubDate>Thu, 11 Jun 2026 20:34:22 GMT</pubDate>
    <itunes:subtitle />
    <itunes:summary />
    <description>The latest answers and comments added to the Question, NLPSolve Matrix Form</description>
    <image>
      <url>http://www.mapleprimes.com/images/mapleprimeswhite.jpg</url>
      <title>MaplePrimes - answers and comments on Question, NLPSolve Matrix Form</title>
      <link>http://www.mapleprimes.com/questions/129419-NLPSolve-Matrix-Form</link>
    </image>
    <item>
      <title>NLP or QP</title>
      <link>http://www.mapleprimes.com/questions/129419-NLPSolve-Matrix-Form?ref=Feed:MaplePrimes:NLPSolve Matrix Form:Comments#answer129514</link>
      <itunes:summary>&lt;p&gt;Is this just a QP minimization problem in disguise, rather than an NLP minimization problem? By which I mean, a quadratic objective and linear constraints?&lt;/p&gt;
&lt;p&gt;Sure, your con3 constraint is nonlinear, involving a 2-norm. But it is the only place that variable `r` appears in constraints, and your objective is simply `r`. So can't you just make the norm part of con3 as a new objective, and then get rid of con3 as a constraint?&lt;/p&gt;
&lt;p&gt;Note that the setup of this problem gets expensive quickly, as `nstock` grows. And there is a lot of room for improvements to the first parts which generate the randomized data. So, unless all that is just a stand-in for some other means of data acquisition then you can get a bit of speedup just by refining all that code. I mean, everything up to the Cholesky decomposition of `Cov`. On the machine used for the timings below, at nstock=200 the construction of `Cov`, `R` and the constraints takes about 70 seconds. What comes before constructing `Cov` can likely be reduced to under 4-5 seconds.&lt;/p&gt;
&lt;p&gt;I set nstock=200 and compared these two Optimization calls below. I'll leave out all the set up here, except for the constraint assignments,&lt;/p&gt;
&lt;pre&gt;con1 := add(W[i], i = 1 .. nstock) &amp;lt;= 1:
con2 := EV.W-pr &amp;gt;= 0:

NRW2 := Norm(R.W, 2, conjugate = false):
con3 := NRW2 - r &amp;lt;= 0:

# As you solved it with NLPSolve...

sol1 := CodeTools:-Usage(NLPSolve(r,{con1,con2,con3},seq(w[i]=0..1,i=1..nstock)));

memory used=1.74GiB, alloc change=55.49MiB, cpu time=60.68s, real time=60.70s

sort(select(t -&amp;gt; rhs(t)&amp;gt;0 and lhs(t)&amp;lt;&amp;gt;r, sol1[2]));

        [w[21] = 0.0270237593173089, w[25] = 0.0322056751304918, 

          w[35] = 0.000847852100225448, w[67] = 0.0492087037211113, 

          w[78] = 0.0438242963135371, w[86] = 0.0416518751919245, 

          w[88] = 0.0417036500369194, w[89] = 0.0717631323305688, 

          w[100] = 0.00837739752003451, w[107] = 0.137179654344253, 

          w[109] = 0.107669160523004, w[125] = 0.0289124908386128, 

          w[131] = 0.160793105594057, w[153] = 0.0236924836513717, 

          w[157] = 0.0341339386566807, w[180] = 0.0119978162730577, 

          w[185] = 0.0405857945037750, w[190] = 0.129027000241401, 

          w[192] = 0.00940221371168578]

r = eval(r, sol1[2]);

                            r = 2.03629907765324

# And now...

sol2 := CodeTools:-Usage(QPSolve(NRW2^2,{con1,con2},seq(w[i]=0..1,i=1..nstock)));

memory used=448.67MiB, alloc change=0 bytes, cpu time=7.71s, real time=7.72s

sort(t -&amp;gt; rhs(t)&amp;gt;0 and lhs(t) &amp;lt;&amp;gt; r, sol2[2]));

        [w[21] = 0.0270237589337289, w[25] = 0.0322056750319796, 

          w[35] = 0.000847852090717340, w[67] = 0.0492087042316293, 

          w[78] = 0.0438242958978819, w[86] = 0.0416518740369907, 

          w[88] = 0.0417036488838085, w[89] = 0.0717631314373649, 

          w[100] = 0.00837739703763107, w[107] = 0.137179652525067, 

          w[109] = 0.107669163079282, w[125] = 0.0289124902420816, 

          w[131] = 0.160793108650386, w[153] = 0.0236924831211481, 

          w[157] = 0.0341339380256316, w[180] = 0.0119978167550648, 

          w[185] = 0.0405857946727649, w[190] = 0.129027001732921, 

          w[192] = 0.00940221361388309]

r = sqrt(eval(NRW2^2, sol2[2])); # `r` in the original sense of `con3`

                            r = 2.03629907765382
&lt;/pre&gt;
&lt;p&gt;Unless I did something quite wrong, those two attempts produce essentially the same solution, but the QPSolve is 7 times faster.&lt;/p&gt;
&lt;p&gt;And the QPSolve use can likely also be improved using Matrix form for its input.&lt;/p&gt;
&lt;!--break--&gt;
&lt;p&gt;acer&lt;/p&gt;</itunes:summary>
      <description>&lt;p&gt;Is this just a QP minimization problem in disguise, rather than an NLP minimization problem? By which I mean, a quadratic objective and linear constraints?&lt;/p&gt;
&lt;p&gt;Sure, your con3 constraint is nonlinear, involving a 2-norm. But it is the only place that variable `r` appears in constraints, and your objective is simply `r`. So can't you just make the norm part of con3 as a new objective, and then get rid of con3 as a constraint?&lt;/p&gt;
&lt;p&gt;Note that the setup of this problem gets expensive quickly, as `nstock` grows. And there is a lot of room for improvements to the first parts which generate the randomized data. So, unless all that is just a stand-in for some other means of data acquisition then you can get a bit of speedup just by refining all that code. I mean, everything up to the Cholesky decomposition of `Cov`. On the machine used for the timings below, at nstock=200 the construction of `Cov`, `R` and the constraints takes about 70 seconds. What comes before constructing `Cov` can likely be reduced to under 4-5 seconds.&lt;/p&gt;
&lt;p&gt;I set nstock=200 and compared these two Optimization calls below. I'll leave out all the set up here, except for the constraint assignments,&lt;/p&gt;
&lt;pre&gt;con1 := add(W[i], i = 1 .. nstock) &amp;lt;= 1:
con2 := EV.W-pr &amp;gt;= 0:

NRW2 := Norm(R.W, 2, conjugate = false):
con3 := NRW2 - r &amp;lt;= 0:

# As you solved it with NLPSolve...

sol1 := CodeTools:-Usage(NLPSolve(r,{con1,con2,con3},seq(w[i]=0..1,i=1..nstock)));

memory used=1.74GiB, alloc change=55.49MiB, cpu time=60.68s, real time=60.70s

sort(select(t -&amp;gt; rhs(t)&amp;gt;0 and lhs(t)&amp;lt;&amp;gt;r, sol1[2]));

        [w[21] = 0.0270237593173089, w[25] = 0.0322056751304918, 

          w[35] = 0.000847852100225448, w[67] = 0.0492087037211113, 

          w[78] = 0.0438242963135371, w[86] = 0.0416518751919245, 

          w[88] = 0.0417036500369194, w[89] = 0.0717631323305688, 

          w[100] = 0.00837739752003451, w[107] = 0.137179654344253, 

          w[109] = 0.107669160523004, w[125] = 0.0289124908386128, 

          w[131] = 0.160793105594057, w[153] = 0.0236924836513717, 

          w[157] = 0.0341339386566807, w[180] = 0.0119978162730577, 

          w[185] = 0.0405857945037750, w[190] = 0.129027000241401, 

          w[192] = 0.00940221371168578]

r = eval(r, sol1[2]);

                            r = 2.03629907765324

# And now...

sol2 := CodeTools:-Usage(QPSolve(NRW2^2,{con1,con2},seq(w[i]=0..1,i=1..nstock)));

memory used=448.67MiB, alloc change=0 bytes, cpu time=7.71s, real time=7.72s

sort(t -&amp;gt; rhs(t)&amp;gt;0 and lhs(t) &amp;lt;&amp;gt; r, sol2[2]));

        [w[21] = 0.0270237589337289, w[25] = 0.0322056750319796, 

          w[35] = 0.000847852090717340, w[67] = 0.0492087042316293, 

          w[78] = 0.0438242958978819, w[86] = 0.0416518740369907, 

          w[88] = 0.0417036488838085, w[89] = 0.0717631314373649, 

          w[100] = 0.00837739703763107, w[107] = 0.137179652525067, 

          w[109] = 0.107669163079282, w[125] = 0.0289124902420816, 

          w[131] = 0.160793108650386, w[153] = 0.0236924831211481, 

          w[157] = 0.0341339380256316, w[180] = 0.0119978167550648, 

          w[185] = 0.0405857946727649, w[190] = 0.129027001732921, 

          w[192] = 0.00940221361388309]

r = sqrt(eval(NRW2^2, sol2[2])); # `r` in the original sense of `con3`

                            r = 2.03629907765382
&lt;/pre&gt;
&lt;p&gt;Unless I did something quite wrong, those two attempts produce essentially the same solution, but the QPSolve is 7 times faster.&lt;/p&gt;
&lt;p&gt;And the QPSolve use can likely also be improved using Matrix form for its input.&lt;/p&gt;
&lt;!--break--&gt;
&lt;p&gt;acer&lt;/p&gt;</description>
      <guid>129514</guid>
      <pubDate>Tue, 10 Jan 2012 14:52:43 Z</pubDate>
      <itunes:author>acer</itunes:author>
      <author>acer</author>
    </item>
    <item>
      <title>acer, you are absolutly correct. It is a</title>
      <link>http://www.mapleprimes.com/questions/129419-NLPSolve-Matrix-Form?ref=Feed:MaplePrimes:NLPSolve Matrix Form:Comments#comment129515</link>
      <itunes:summary>&lt;p&gt;acer, you are absolutly correct. It is a &lt;span&gt;QP minimization problem in disguise&lt;/span&gt;!&lt;br&gt;&lt;br&gt;S=R'.R&amp;nbsp;&amp;nbsp; where S is the covariance matrix and R is the upper triangular &lt;br&gt;factor of the Cholesky Decomposition matrix&lt;br&gt;&lt;br&gt;w'.R'=(R.w)'&amp;nbsp;&amp;nbsp;&amp;nbsp; sqrt(x'x)=norm(x)&lt;br&gt;&lt;br&gt;w'.S.w &amp;lt; r^2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; w'.R'.R.w&amp;lt; r^2&amp;nbsp;&amp;nbsp;&amp;nbsp; (R.w)'.(R.w)&amp;lt; r^2&amp;nbsp;&amp;nbsp;&amp;nbsp; sqrt((R.w)'.(R.w))&amp;lt; sqrt(r^2)&amp;nbsp;&amp;nbsp;&amp;nbsp; norm(R.w)&amp;lt; r&lt;br&gt;&lt;br&gt;&lt;br&gt;Unfortunately, I already know that the QP and the NLP optimization produces &lt;br&gt;the same allocations (even though the objective functions returns different values since the &lt;br&gt;objective is different).&lt;br&gt;&lt;br&gt;And yes, the first part can be made much more efficient.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;# later comment&lt;/strong&gt;-1&lt;br&gt;And yes you are right the two problems can be solved equivalent as:&lt;br&gt;&lt;br&gt;problem := r, {con1, con4, con5}, seq(w[i] = 0 .. 1, i = 1 .. nstock):&lt;br&gt;NLPSolve(Norm(R.W, 2, conjugate = false), {con1, con2, con3, con4}); &lt;br&gt;NLPSolve(problem) ;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;/strong&gt;&lt;br&gt;My question remains though how do I convert it to NLP[Matrix form] using&lt;br&gt;Optimization:-Convert:-AlgebraicForm:-NLPToMatrix(problem)&amp;nbsp;&amp;nbsp; ?????????&lt;br&gt;&lt;br&gt;&lt;strong&gt;# later comment&lt;/strong&gt;-2&lt;br&gt;or alternativly how do you solve Min(Norm(R.W)) with LP?&lt;/p&gt;
&lt;p&gt;&lt;br&gt;restart: &lt;br&gt;randomize(): &lt;br&gt;with(ListTools): &lt;br&gt;with(LinearAlgebra): &lt;br&gt;with(ArrayTools): &lt;br&gt;with(Statistics): &lt;br&gt;with(plots): &lt;br&gt;with(Optimization): &lt;br&gt;&lt;br&gt;n := 40: &lt;br&gt;nstock := 10: &lt;br&gt;A := RandomMatrix(n, nstock, generator = -15 .. 15, outputoptions = [datatype = float[8]]): &lt;br&gt;Cov := CovarianceMatrix(A):&lt;br&gt;EV := Vector([seq(ExpectedValue(Column(A, i)), i = 1 .. nstock)]):&lt;br&gt;R := LUDecomposition(Cov, 'method' = 'Cholesky', output = 'U'): &lt;br&gt;W := Vector([seq(w[i], i = 1 .. nstock)]):&lt;br&gt;&lt;br&gt;pr := .6*max([seq(ExpectedValue(Column(A, i)), i = 1 .. nstock)]):&lt;br&gt;&lt;br&gt;con1 := add(W[i], i = 1 .. nstock) &amp;lt;= 1:&lt;br&gt;con2 := seq(W[i] &amp;lt;= 1, i = 1 .. nstock):&lt;br&gt;con3 := seq(W[i] &amp;gt;= 0, i = 1 .. nstock): &lt;br&gt;con4 := EV.W-pr &amp;gt;= 0:&lt;br&gt;con5 := Norm(R.W, 2, conjugate = false):&lt;br&gt; &lt;br&gt;problem := r, {con1, con4, con5}, seq(w[i] = 0 .. 1, i = 1 .. nstock):&lt;br&gt;problem_matrix_form := Optimization:-Convert:-AlgebraicForm:-NLPToMatrix(problem):&lt;br&gt;&lt;br&gt;QPSolve(Transpose(W).Cov.W, {con1, con2, con3, con4});&amp;nbsp; &lt;br&gt;NLPSolve(problem);&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br&gt;NLPSolve(problem_matrix_form[[1, 2, 8, 9]])&lt;br&gt;&lt;br&gt;&lt;/p&gt;</itunes:summary>
      <description>&lt;p&gt;acer, you are absolutly correct. It is a &lt;span&gt;QP minimization problem in disguise&lt;/span&gt;!&lt;br&gt;&lt;br&gt;S=R'.R&amp;nbsp;&amp;nbsp; where S is the covariance matrix and R is the upper triangular &lt;br&gt;factor of the Cholesky Decomposition matrix&lt;br&gt;&lt;br&gt;w'.R'=(R.w)'&amp;nbsp;&amp;nbsp;&amp;nbsp; sqrt(x'x)=norm(x)&lt;br&gt;&lt;br&gt;w'.S.w &amp;lt; r^2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; w'.R'.R.w&amp;lt; r^2&amp;nbsp;&amp;nbsp;&amp;nbsp; (R.w)'.(R.w)&amp;lt; r^2&amp;nbsp;&amp;nbsp;&amp;nbsp; sqrt((R.w)'.(R.w))&amp;lt; sqrt(r^2)&amp;nbsp;&amp;nbsp;&amp;nbsp; norm(R.w)&amp;lt; r&lt;br&gt;&lt;br&gt;&lt;br&gt;Unfortunately, I already know that the QP and the NLP optimization produces &lt;br&gt;the same allocations (even though the objective functions returns different values since the &lt;br&gt;objective is different).&lt;br&gt;&lt;br&gt;And yes, the first part can be made much more efficient.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;# later comment&lt;/strong&gt;-1&lt;br&gt;And yes you are right the two problems can be solved equivalent as:&lt;br&gt;&lt;br&gt;problem := r, {con1, con4, con5}, seq(w[i] = 0 .. 1, i = 1 .. nstock):&lt;br&gt;NLPSolve(Norm(R.W, 2, conjugate = false), {con1, con2, con3, con4}); &lt;br&gt;NLPSolve(problem) ;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;/strong&gt;&lt;br&gt;My question remains though how do I convert it to NLP[Matrix form] using&lt;br&gt;Optimization:-Convert:-AlgebraicForm:-NLPToMatrix(problem)&amp;nbsp;&amp;nbsp; ?????????&lt;br&gt;&lt;br&gt;&lt;strong&gt;# later comment&lt;/strong&gt;-2&lt;br&gt;or alternativly how do you solve Min(Norm(R.W)) with LP?&lt;/p&gt;
&lt;p&gt;&lt;br&gt;restart: &lt;br&gt;randomize(): &lt;br&gt;with(ListTools): &lt;br&gt;with(LinearAlgebra): &lt;br&gt;with(ArrayTools): &lt;br&gt;with(Statistics): &lt;br&gt;with(plots): &lt;br&gt;with(Optimization): &lt;br&gt;&lt;br&gt;n := 40: &lt;br&gt;nstock := 10: &lt;br&gt;A := RandomMatrix(n, nstock, generator = -15 .. 15, outputoptions = [datatype = float[8]]): &lt;br&gt;Cov := CovarianceMatrix(A):&lt;br&gt;EV := Vector([seq(ExpectedValue(Column(A, i)), i = 1 .. nstock)]):&lt;br&gt;R := LUDecomposition(Cov, 'method' = 'Cholesky', output = 'U'): &lt;br&gt;W := Vector([seq(w[i], i = 1 .. nstock)]):&lt;br&gt;&lt;br&gt;pr := .6*max([seq(ExpectedValue(Column(A, i)), i = 1 .. nstock)]):&lt;br&gt;&lt;br&gt;con1 := add(W[i], i = 1 .. nstock) &amp;lt;= 1:&lt;br&gt;con2 := seq(W[i] &amp;lt;= 1, i = 1 .. nstock):&lt;br&gt;con3 := seq(W[i] &amp;gt;= 0, i = 1 .. nstock): &lt;br&gt;con4 := EV.W-pr &amp;gt;= 0:&lt;br&gt;con5 := Norm(R.W, 2, conjugate = false):&lt;br&gt; &lt;br&gt;problem := r, {con1, con4, con5}, seq(w[i] = 0 .. 1, i = 1 .. nstock):&lt;br&gt;problem_matrix_form := Optimization:-Convert:-AlgebraicForm:-NLPToMatrix(problem):&lt;br&gt;&lt;br&gt;QPSolve(Transpose(W).Cov.W, {con1, con2, con3, con4});&amp;nbsp; &lt;br&gt;NLPSolve(problem);&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br&gt;NLPSolve(problem_matrix_form[[1, 2, 8, 9]])&lt;br&gt;&lt;br&gt;&lt;/p&gt;</description>
      <guid>129515</guid>
      <pubDate>Tue, 10 Jan 2012 15:32:32 Z</pubDate>
      <itunes:author>alex_01</itunes:author>
      <author>alex_01</author>
    </item>
    <item>
      <title>con1..con2(con3)?</title>
      <link>http://www.mapleprimes.com/questions/129419-NLPSolve-Matrix-Form?ref=Feed:MaplePrimes:NLPSolve Matrix Form:Comments#comment129540</link>
      <itunes:summary>&lt;p&gt;&lt;a href="http://www.mapleprimes.com/questions/129419-NLPSolve-Matrix-Form#comment129515"&gt;@alex_01&lt;/a&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;con1 := add(W[i], i = 1 .. nstock) con2 := seq(W[i] con3 := seq(W[i] &amp;gt;= 0, i = 1 .. nstock): &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span class="short_text"&gt;&lt;span style="background-color: #ffffff;"&gt;does not work. &lt;/span&gt;&lt;span style="background-color: #ffffff;"&gt;I do not understand the syntax&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;</itunes:summary>
      <description>&lt;p&gt;&lt;a href="http://www.mapleprimes.com/questions/129419-NLPSolve-Matrix-Form#comment129515"&gt;@alex_01&lt;/a&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;con1 := add(W[i], i = 1 .. nstock) con2 := seq(W[i] con3 := seq(W[i] &amp;gt;= 0, i = 1 .. nstock): &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span class="short_text"&gt;&lt;span style="background-color: #ffffff;"&gt;does not work. &lt;/span&gt;&lt;span style="background-color: #ffffff;"&gt;I do not understand the syntax&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;</description>
      <guid>129540</guid>
      <pubDate>Wed, 11 Jan 2012 02:38:20 Z</pubDate>
      <itunes:author>herclau</itunes:author>
      <author>herclau</author>
    </item>
    <item>
      <title>@herclau sorry about that. I have to copy</title>
      <link>http://www.mapleprimes.com/questions/129419-NLPSolve-Matrix-Form?ref=Feed:MaplePrimes:NLPSolve Matrix Form:Comments#comment129541</link>
      <itunes:summary>&lt;p&gt;&lt;a href="http://www.mapleprimes.com/questions/129419-NLPSolve-Matrix-Form#comment129540"&gt;@herclau&lt;/a&gt; sorry about that. I have to copy from maple and then past into a &lt;br&gt;wordpad and then rearange everything to be able to post the code here.&lt;br&gt;&lt;br&gt;I have uppdated the constraints...but it still dont work as it should.&lt;/p&gt;</itunes:summary>
      <description>&lt;p&gt;&lt;a href="http://www.mapleprimes.com/questions/129419-NLPSolve-Matrix-Form#comment129540"&gt;@herclau&lt;/a&gt; sorry about that. I have to copy from maple and then past into a &lt;br&gt;wordpad and then rearange everything to be able to post the code here.&lt;br&gt;&lt;br&gt;I have uppdated the constraints...but it still dont work as it should.&lt;/p&gt;</description>
      <guid>129541</guid>
      <pubDate>Wed, 11 Jan 2012 03:41:00 Z</pubDate>
      <itunes:author>alex_01</itunes:author>
      <author>alex_01</author>
    </item>
    <item>
      <title>let's see now...</title>
      <link>http://www.mapleprimes.com/questions/129419-NLPSolve-Matrix-Form?ref=Feed:MaplePrimes:NLPSolve Matrix Form:Comments#comment129542</link>
      <itunes:summary>&lt;p&gt;&lt;a href="http://www.mapleprimes.com/questions/129419-NLPSolve-Matrix-Form#comment129515"&gt;@alex_01&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;You wrote, "&lt;strong&gt;later comment&lt;/strong&gt;&lt;span&gt;-2&lt;/span&gt;... how do you solve Min(Norm(R.W)) with LP?", and incidentally you were using the 2-norm.&lt;/p&gt;
&lt;p&gt;Well, that is not a linear objective so it isn't a &lt;a href="http://en.wikipedia.org/wiki/Linear_programming"&gt;Linear Programming&lt;/a&gt; problem, so `LPSolve` won't solve that formulation. I showed that your posted problem can be taken as a &lt;a href="http://en.wikipedia.org/wiki/Quadratic_programming"&gt;Quadratic Programming&lt;/a&gt; problem with a quadratic objective and linear constraints, and you agreed. What now are your grounds for thinking that it can also be reformulated as an equivalent LP problem!?&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;You also wrote, "Unfortunately, I already know that the QP and the NLP optimization produces the same allocations..." which makes it sound as if you are unhappy with the computed solution, and are hoping for a better one. But this (according to evidence from you) is a convex QP problem and the objective is bounded from below in the feasibility region, so the computed solution should be globally optimal. How then can you hope for a better solution!?&lt;/p&gt;
&lt;p&gt;The only way that I can currently envision getting a more desirable solution is if you have additional qualifying restrictions or constraints in mind (but as yet not stated in this thread). For example, perhaps you want an integer-valued solution (well, binary valued, for these ranges), which is something that I just make up as an example. Do you have additional constraints?&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;So, you want to construct the Matrix form for the NLP formulation of this QP class problem. Why is that? Is it so that you can form procedures for objective, constraints, objective gradient, and constraint jacobian which all accept purely numeric vector arguments, compute results and fill some arguments with the results inplace, and that is evalhf'able or ideally even compilable? And you want them highly optimized and tuned to the quadratic &amp;amp; linear natures of the relevant formulas? It can be done (though keeping down overhead from callbacks through main Maple to get from external Optimization wrappers to Compiled procs is awkward).&lt;/p&gt;
&lt;p&gt;But you know who's already done that, without any bypass overhead? The &lt;a href="http://www.nag.co.uk/"&gt;Numerical Algorithms Group&lt;/a&gt;. They wrote all the specialized QP objective, linear constraint evaluation, and gradient/jacobian/hessian stuff and compiled it, together. And Maple's Optimization:-QPSolve passes the float[8] data of the QP Matrix form to NAG's &lt;a href="http://www.nag.co.uk/numeric/cl/nagdoc_cl08/pdf/E04/e04nfc.pdf"&gt;e04nfa&lt;/a&gt; via Optimization:-External:-E04NFA.&lt;/p&gt;
&lt;p&gt;Are your problems so large and sparse that e04nfa is not good enough? How much specialized optimization to the procs and code do you think you can muster, to make up for what appears to be a speed difference factor of about 7 between QPSolve and NLPSolve used plainly.&lt;/p&gt;
&lt;p&gt;Look, I don't want to be rude, but it's a little frustrating that you still seem so very disinclined to believe my advice. You wanted to do QP, so &lt;a href="http://www.mapleprimes.com/questions/128291-Maximize-Risk-Adjusted-Return-In-QP-Matrix-Form"&gt;I set up&lt;/a&gt; the Matrix form and explained it. You wanted to do LP, so &lt;a href="http://www.mapleprimes.com/questions/129179-LPSolve-Matrix-Form"&gt;I set up&lt;/a&gt; the Matrix form and explained it. Why not believe what I suggest about this route into NLP?&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I'm also still confused about how much it seems to matter to you whether a 7 second (nstock=200) code section is 100% doubleplus-interior-point-semidefinite-cone-fantastic when the preamble before it is running 80 seconds instead of 30 or so. But then, you have to date left unanswered queries as to how large your typical problems will be.&lt;/p&gt;</itunes:summary>
      <description>&lt;p&gt;&lt;a href="http://www.mapleprimes.com/questions/129419-NLPSolve-Matrix-Form#comment129515"&gt;@alex_01&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;You wrote, "&lt;strong&gt;later comment&lt;/strong&gt;&lt;span&gt;-2&lt;/span&gt;... how do you solve Min(Norm(R.W)) with LP?", and incidentally you were using the 2-norm.&lt;/p&gt;
&lt;p&gt;Well, that is not a linear objective so it isn't a &lt;a href="http://en.wikipedia.org/wiki/Linear_programming"&gt;Linear Programming&lt;/a&gt; problem, so `LPSolve` won't solve that formulation. I showed that your posted problem can be taken as a &lt;a href="http://en.wikipedia.org/wiki/Quadratic_programming"&gt;Quadratic Programming&lt;/a&gt; problem with a quadratic objective and linear constraints, and you agreed. What now are your grounds for thinking that it can also be reformulated as an equivalent LP problem!?&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;You also wrote, "Unfortunately, I already know that the QP and the NLP optimization produces the same allocations..." which makes it sound as if you are unhappy with the computed solution, and are hoping for a better one. But this (according to evidence from you) is a convex QP problem and the objective is bounded from below in the feasibility region, so the computed solution should be globally optimal. How then can you hope for a better solution!?&lt;/p&gt;
&lt;p&gt;The only way that I can currently envision getting a more desirable solution is if you have additional qualifying restrictions or constraints in mind (but as yet not stated in this thread). For example, perhaps you want an integer-valued solution (well, binary valued, for these ranges), which is something that I just make up as an example. Do you have additional constraints?&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;So, you want to construct the Matrix form for the NLP formulation of this QP class problem. Why is that? Is it so that you can form procedures for objective, constraints, objective gradient, and constraint jacobian which all accept purely numeric vector arguments, compute results and fill some arguments with the results inplace, and that is evalhf'able or ideally even compilable? And you want them highly optimized and tuned to the quadratic &amp;amp; linear natures of the relevant formulas? It can be done (though keeping down overhead from callbacks through main Maple to get from external Optimization wrappers to Compiled procs is awkward).&lt;/p&gt;
&lt;p&gt;But you know who's already done that, without any bypass overhead? The &lt;a href="http://www.nag.co.uk/"&gt;Numerical Algorithms Group&lt;/a&gt;. They wrote all the specialized QP objective, linear constraint evaluation, and gradient/jacobian/hessian stuff and compiled it, together. And Maple's Optimization:-QPSolve passes the float[8] data of the QP Matrix form to NAG's &lt;a href="http://www.nag.co.uk/numeric/cl/nagdoc_cl08/pdf/E04/e04nfc.pdf"&gt;e04nfa&lt;/a&gt; via Optimization:-External:-E04NFA.&lt;/p&gt;
&lt;p&gt;Are your problems so large and sparse that e04nfa is not good enough? How much specialized optimization to the procs and code do you think you can muster, to make up for what appears to be a speed difference factor of about 7 between QPSolve and NLPSolve used plainly.&lt;/p&gt;
&lt;p&gt;Look, I don't want to be rude, but it's a little frustrating that you still seem so very disinclined to believe my advice. You wanted to do QP, so &lt;a href="http://www.mapleprimes.com/questions/128291-Maximize-Risk-Adjusted-Return-In-QP-Matrix-Form"&gt;I set up&lt;/a&gt; the Matrix form and explained it. You wanted to do LP, so &lt;a href="http://www.mapleprimes.com/questions/129179-LPSolve-Matrix-Form"&gt;I set up&lt;/a&gt; the Matrix form and explained it. Why not believe what I suggest about this route into NLP?&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I'm also still confused about how much it seems to matter to you whether a 7 second (nstock=200) code section is 100% doubleplus-interior-point-semidefinite-cone-fantastic when the preamble before it is running 80 seconds instead of 30 or so. But then, you have to date left unanswered queries as to how large your typical problems will be.&lt;/p&gt;</description>
      <guid>129542</guid>
      <pubDate>Wed, 11 Jan 2012 07:46:51 Z</pubDate>
      <itunes:author>acer</itunes:author>
      <author>acer</author>
    </item>
    <item>
      <title>@acer You seem to misunderstand my intentions</title>
      <link>http://www.mapleprimes.com/questions/129419-NLPSolve-Matrix-Form?ref=Feed:MaplePrimes:NLPSolve Matrix Form:Comments#comment129544</link>
      <itunes:summary>&lt;p&gt;&lt;a href="http://www.mapleprimes.com/questions/129419-NLPSolve-Matrix-Form#comment129542"&gt;@acer&lt;/a&gt; You seem to misunderstand my intentions a bit. All I want is to be able to express all &lt;br&gt;my numerous different problems in all different kinds of forms ie algebraic or matrix form. &lt;br&gt;Now the notation for matrix form is more complex hence it is more difficult to set up such &lt;br&gt;a problems not to mention the notation for NLP[mtrix form] which is even more complex. &lt;br&gt;&lt;br&gt;That was the reasons why I liked the &lt;span class="mainBody document"&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;Optimization:-Convert:-AlgebraicForm:-&lt;br&gt;LPToMatrix(problem) solution because it gave you something to hold one to. &lt;br&gt;Instead of just trying stuff randomly and gettting error messages slaped in your face&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt; &lt;br&gt;when you are trying to convert you problem to matrix form you could actually see what &lt;br&gt;the final result of your specific problem should look like in matrix form. &lt;br&gt;Which made things a little bit easier.&lt;br&gt;&lt;br&gt;However, I recently discovered that such a solution is not necessarily the "holy grail" because &lt;br&gt;even though it gives you the final results it does not explain how it got there. For simple &lt;br&gt;problems that might be easy to figure out but for complex problems that is a whole different &lt;br&gt;ball game. As you pointed out you cant just do the&amp;nbsp;&lt;span class="mainBody document"&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;Optimization:-Convert:-AlgebraicForm:-&lt;br&gt;LPToMatrix(problem) &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt; and hope for a speed up but you need to rewrite the output in float &lt;br&gt;matricies, hence you need to understand how those matricies where generated in&lt;br&gt;order to be able to set up more general problems like if you change the number of data &lt;br&gt;columns ie the number of stocks or the number of observations etc etc&lt;br&gt;&lt;br&gt;Its not like I dont believe your advice. I do believe that for this particular problem &lt;br&gt;QPSolve[Matrix Form] might be the fastest and the most appropriate to use however that &lt;br&gt;does not mean that in the future I will not be faced with the task of converting another NLP to &lt;br&gt;matrix form. Hence, it would be nice at this stage to have such knowledge so the conversion &lt;br&gt;can be as painless as possible. This specific problem represent just one of many&lt;br&gt;different problems I have in my computer.&lt;br&gt;&lt;br&gt;Also I am glad that you pointed out that &lt;span&gt;Min(Norm(R.W)) is not linear hence LP cant be used! &lt;br&gt;Then I dont have to bang my head against the wall trying to figure it out (&lt;/span&gt;I always have the &lt;br&gt;insecure feeling that LP is better than QP since some people use LP to solve problems with 10's &lt;br&gt;of thousands of variables and constrainst (not in maple though) but this might be wrong. I also &lt;br&gt;have the insecure feeling that Cone programming is the most efficient of them all but this might &lt;br&gt;also be wrong)&amp;nbsp; &lt;br&gt;&lt;br&gt;For example if you look in the begining of Chapter 10 in this referens (Boyd etc, which &lt;br&gt;apperently is an expert in optimization )&lt;br&gt;&lt;br&gt;&lt;a href="http://www.ee.ucla.edu/~vandenbe/103/reader.pdf"&gt;http://www.ee.ucla.edu/~vandenbe/103/reader.pdf&lt;/a&gt;&lt;br&gt;&lt;br&gt;They state that the solution to the least-norm problem ie norm(x) Ax=b is unique and given by&lt;br&gt;x = A' (AA') ^(-1) .b which means (I quote) "that we can solve the least-norm problem by solving&lt;br&gt;(AA').z=b&amp;nbsp; (10.2) and then calculating &amp;circ;x = A'.z. The equations (10.2) are a set of m &lt;em&gt;linear equations&lt;/em&gt;&lt;br&gt;in m variables, and are called the normal equations associated with the least-norm problem.&lt;br&gt;&lt;br&gt;My specific problem is a little bit different (even though they are both min norm problems) hence it &lt;br&gt;was difficult to determind if my problem was linear or not.&lt;br&gt;&lt;br&gt;&lt;/p&gt;</itunes:summary>
      <description>&lt;p&gt;&lt;a href="http://www.mapleprimes.com/questions/129419-NLPSolve-Matrix-Form#comment129542"&gt;@acer&lt;/a&gt; You seem to misunderstand my intentions a bit. All I want is to be able to express all &lt;br&gt;my numerous different problems in all different kinds of forms ie algebraic or matrix form. &lt;br&gt;Now the notation for matrix form is more complex hence it is more difficult to set up such &lt;br&gt;a problems not to mention the notation for NLP[mtrix form] which is even more complex. &lt;br&gt;&lt;br&gt;That was the reasons why I liked the &lt;span class="mainBody document"&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;Optimization:-Convert:-AlgebraicForm:-&lt;br&gt;LPToMatrix(problem) solution because it gave you something to hold one to. &lt;br&gt;Instead of just trying stuff randomly and gettting error messages slaped in your face&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt; &lt;br&gt;when you are trying to convert you problem to matrix form you could actually see what &lt;br&gt;the final result of your specific problem should look like in matrix form. &lt;br&gt;Which made things a little bit easier.&lt;br&gt;&lt;br&gt;However, I recently discovered that such a solution is not necessarily the "holy grail" because &lt;br&gt;even though it gives you the final results it does not explain how it got there. For simple &lt;br&gt;problems that might be easy to figure out but for complex problems that is a whole different &lt;br&gt;ball game. As you pointed out you cant just do the&amp;nbsp;&lt;span class="mainBody document"&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;Optimization:-Convert:-AlgebraicForm:-&lt;br&gt;LPToMatrix(problem) &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt; and hope for a speed up but you need to rewrite the output in float &lt;br&gt;matricies, hence you need to understand how those matricies where generated in&lt;br&gt;order to be able to set up more general problems like if you change the number of data &lt;br&gt;columns ie the number of stocks or the number of observations etc etc&lt;br&gt;&lt;br&gt;Its not like I dont believe your advice. I do believe that for this particular problem &lt;br&gt;QPSolve[Matrix Form] might be the fastest and the most appropriate to use however that &lt;br&gt;does not mean that in the future I will not be faced with the task of converting another NLP to &lt;br&gt;matrix form. Hence, it would be nice at this stage to have such knowledge so the conversion &lt;br&gt;can be as painless as possible. This specific problem represent just one of many&lt;br&gt;different problems I have in my computer.&lt;br&gt;&lt;br&gt;Also I am glad that you pointed out that &lt;span&gt;Min(Norm(R.W)) is not linear hence LP cant be used! &lt;br&gt;Then I dont have to bang my head against the wall trying to figure it out (&lt;/span&gt;I always have the &lt;br&gt;insecure feeling that LP is better than QP since some people use LP to solve problems with 10's &lt;br&gt;of thousands of variables and constrainst (not in maple though) but this might be wrong. I also &lt;br&gt;have the insecure feeling that Cone programming is the most efficient of them all but this might &lt;br&gt;also be wrong)&amp;nbsp; &lt;br&gt;&lt;br&gt;For example if you look in the begining of Chapter 10 in this referens (Boyd etc, which &lt;br&gt;apperently is an expert in optimization )&lt;br&gt;&lt;br&gt;&lt;a href="http://www.ee.ucla.edu/~vandenbe/103/reader.pdf"&gt;http://www.ee.ucla.edu/~vandenbe/103/reader.pdf&lt;/a&gt;&lt;br&gt;&lt;br&gt;They state that the solution to the least-norm problem ie norm(x) Ax=b is unique and given by&lt;br&gt;x = A' (AA') ^(-1) .b which means (I quote) "that we can solve the least-norm problem by solving&lt;br&gt;(AA').z=b&amp;nbsp; (10.2) and then calculating &amp;circ;x = A'.z. The equations (10.2) are a set of m &lt;em&gt;linear equations&lt;/em&gt;&lt;br&gt;in m variables, and are called the normal equations associated with the least-norm problem.&lt;br&gt;&lt;br&gt;My specific problem is a little bit different (even though they are both min norm problems) hence it &lt;br&gt;was difficult to determind if my problem was linear or not.&lt;br&gt;&lt;br&gt;&lt;/p&gt;</description>
      <guid>129544</guid>
      <pubDate>Wed, 11 Jan 2012 14:26:45 Z</pubDate>
      <itunes:author>alex_01</itunes:author>
      <author>alex_01</author>
    </item>
  </channel>
</rss>