<rss xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" version="2.0">
  <channel>
    <title>MaplePrimes - answers and comments on Question, Help with an Optimization Problem using NLPSolve</title>
    <link>http://www.mapleprimes.com/questions/36929-Help-With-An-Optimization-Problem-Using-NLPSolve</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 09:02:46 GMT</lastBuildDate>
    <pubDate>Sat, 13 Jun 2026 09:02:46 GMT</pubDate>
    <itunes:subtitle />
    <itunes:summary />
    <description>The latest answers and comments added to the Question, Help with an Optimization Problem using NLPSolve</description>
    <image>
      <url>http://www.mapleprimes.com/images/mapleprimeswhite.jpg</url>
      <title>MaplePrimes - answers and comments on Question, Help with an Optimization Problem using NLPSolve</title>
      <link>http://www.mapleprimes.com/questions/36929-Help-With-An-Optimization-Problem-Using-NLPSolve</link>
    </image>
    <item>
      <title>source</title>
      <link>http://www.mapleprimes.com/questions/36929-Help-With-An-Optimization-Problem-Using-NLPSolve?ref=Feed:MaplePrimes:Help with an Optimization Problem using NLPSolve:Comments#answer64472</link>
      <itunes:summary>&lt;p&gt;Could you post the actual code, or upload a worksheet for that to this site?&lt;/p&gt;
&lt;p&gt;acer&lt;/p&gt;</itunes:summary>
      <description>&lt;p&gt;Could you post the actual code, or upload a worksheet for that to this site?&lt;/p&gt;
&lt;p&gt;acer&lt;/p&gt;</description>
      <guid>64472</guid>
      <pubDate>Thu, 06 Aug 2009 07:20:27 Z</pubDate>
      <itunes:author>acer</itunes:author>
      <author>acer</author>
    </item>
    <item>
      <title>Actual code</title>
      <link>http://www.mapleprimes.com/questions/36929-Help-With-An-Optimization-Problem-Using-NLPSolve?ref=Feed:MaplePrimes:Help with an Optimization Problem using NLPSolve:Comments#answer64473</link>
      <itunes:summary>&lt;p&gt;Sorry, I probably should have just posted this in the beginning.&lt;/p&gt;
&lt;p&gt;&amp;gt; restart;  &lt;/p&gt;
&lt;p&gt;&amp;gt; with(plots);  &lt;/p&gt;
&lt;p&gt;&amp;gt; with(LinearAlgebra);&lt;/p&gt;
&lt;p&gt;&amp;gt; with(ArrayTools);   &lt;/p&gt;
&lt;p&gt;# These data are from earlier calculations which are rather time consuming &lt;/p&gt;
&lt;p&gt;&amp;gt; A := ImportVector(ROMA); Pe := ImportVector(ROMPe); B := ImportMatrix(ROMB); Phi := ImportMatrix(ROMPhi); beta := ImportVector(ROMBeta); N := ImportVector(ROMN); Y := ImportVector(ROMY); ypos := ImportVector(ROMypos); timestep := ImportVector(ROMtimestep); &lt;/p&gt;
&lt;p&gt;&amp;gt; na := Size(A, 1); n := Size(Phi, 2); nn := Size(Phi, 1); nPe := Size(Pe, 1); nypos := Size(ypos, 1); ntimestep := Size(timestep, 1);   &lt;/p&gt;
&lt;p&gt;# K contains parameter values on which the reduced order model is based   &lt;/p&gt;
&lt;p&gt;&amp;gt; K := Matrix(1 .. n, 1 .. 1); ii := 1; for i to na do for j to nPe do K[ii] := A[i]; ii := ii+1 end do end do;  &lt;/p&gt;
&lt;p&gt;&amp;gt; K1 := Matrix(1 .. n, 1 .. 1); ii := 1; for i to na do for j to nPe do K1[ii] := Pe[j]; ii := ii+1 end do end do;  &amp;gt; K := Concatenate(2, K, K1);   &lt;/p&gt;
&lt;p&gt;# F contains an interpolation for any parameters within the range I specified in vectors A and Pe &lt;/p&gt;
&lt;p&gt;&amp;gt; F := Matrix(n, datatype = float[8]); for i to n do for j to n do F[i, j] := evalf(1/sqrt(((K[i, 1]-K[j, 1])/A[na])^2+((K[i, 2]-K[j, 2])/Pe[nPe])^2+1)) end do end do;  &lt;/p&gt;
&lt;p&gt;&amp;gt; UF, SigF, VFt := SingularValues(F, output = ['U', 'S', 'Vt']);  &amp;gt; SF := Vector(n); for i to n do SF[i] := 1/SigF[i] end do;&lt;/p&gt;
&lt;p&gt;&amp;gt; SF := DiagonalMatrix(SF, n, n); &lt;/p&gt;
&lt;p&gt;&amp;gt; Fpsinv := VFt^%T.SF.UF^%T; &lt;/p&gt;
&lt;p&gt;&amp;gt; C := B.Fpsinv;  &lt;/p&gt;
&lt;p&gt;&amp;gt; Nodes := ImportVector(NodesTemp);   &lt;/p&gt;
&lt;p&gt;# f contains the interpolation for a specific case (in this case, the parameters from which the dataset &amp;quot;Nodes&amp;quot; is calculated)--Kguess is a 2 element vector containing these unknown parameters   &lt;/p&gt;
&lt;p&gt;&amp;gt; f := Vector(n); for i to n do f[i] := evalf(1/sqrt(((Kguess[1]-K[i, 1])/A[na])^2+((Kguess[2]-K[i, 2])/Pe[nPe])^2+1)) end do; &lt;/p&gt;
&lt;p&gt;&amp;gt; ROM := evalf(Phi.C.f);  &amp;gt; ObjectiveFunction := Vector(nn); for i to nn do ObjectiveFunction[i] := evalf((Nodes[i]-ROM[i])/Nodes[i]) end do;  &lt;/p&gt;
&lt;p&gt;&amp;gt; p := proc (Kguess) evalf(add(ObjectiveFunction[i], i = 1 .. nn)/nn) end proc;  &lt;/p&gt;
&lt;p&gt;&amp;gt; Optimization[NLPSolve](2, p, assume = nonnegative);  &lt;/p&gt;
&lt;p&gt;Error, (in Optimization:-NLPSolve) non-numeric result encountered    &lt;/p&gt;
&lt;p&gt;Let me know if there's some newbish mistake that I've made. :)&lt;/p&gt;</itunes:summary>
      <description>&lt;p&gt;Sorry, I probably should have just posted this in the beginning.&lt;/p&gt;
&lt;p&gt;&amp;gt; restart;  &lt;/p&gt;
&lt;p&gt;&amp;gt; with(plots);  &lt;/p&gt;
&lt;p&gt;&amp;gt; with(LinearAlgebra);&lt;/p&gt;
&lt;p&gt;&amp;gt; with(ArrayTools);   &lt;/p&gt;
&lt;p&gt;# These data are from earlier calculations which are rather time consuming &lt;/p&gt;
&lt;p&gt;&amp;gt; A := ImportVector(ROMA); Pe := ImportVector(ROMPe); B := ImportMatrix(ROMB); Phi := ImportMatrix(ROMPhi); beta := ImportVector(ROMBeta); N := ImportVector(ROMN); Y := ImportVector(ROMY); ypos := ImportVector(ROMypos); timestep := ImportVector(ROMtimestep); &lt;/p&gt;
&lt;p&gt;&amp;gt; na := Size(A, 1); n := Size(Phi, 2); nn := Size(Phi, 1); nPe := Size(Pe, 1); nypos := Size(ypos, 1); ntimestep := Size(timestep, 1);   &lt;/p&gt;
&lt;p&gt;# K contains parameter values on which the reduced order model is based   &lt;/p&gt;
&lt;p&gt;&amp;gt; K := Matrix(1 .. n, 1 .. 1); ii := 1; for i to na do for j to nPe do K[ii] := A[i]; ii := ii+1 end do end do;  &lt;/p&gt;
&lt;p&gt;&amp;gt; K1 := Matrix(1 .. n, 1 .. 1); ii := 1; for i to na do for j to nPe do K1[ii] := Pe[j]; ii := ii+1 end do end do;  &amp;gt; K := Concatenate(2, K, K1);   &lt;/p&gt;
&lt;p&gt;# F contains an interpolation for any parameters within the range I specified in vectors A and Pe &lt;/p&gt;
&lt;p&gt;&amp;gt; F := Matrix(n, datatype = float[8]); for i to n do for j to n do F[i, j] := evalf(1/sqrt(((K[i, 1]-K[j, 1])/A[na])^2+((K[i, 2]-K[j, 2])/Pe[nPe])^2+1)) end do end do;  &lt;/p&gt;
&lt;p&gt;&amp;gt; UF, SigF, VFt := SingularValues(F, output = ['U', 'S', 'Vt']);  &amp;gt; SF := Vector(n); for i to n do SF[i] := 1/SigF[i] end do;&lt;/p&gt;
&lt;p&gt;&amp;gt; SF := DiagonalMatrix(SF, n, n); &lt;/p&gt;
&lt;p&gt;&amp;gt; Fpsinv := VFt^%T.SF.UF^%T; &lt;/p&gt;
&lt;p&gt;&amp;gt; C := B.Fpsinv;  &lt;/p&gt;
&lt;p&gt;&amp;gt; Nodes := ImportVector(NodesTemp);   &lt;/p&gt;
&lt;p&gt;# f contains the interpolation for a specific case (in this case, the parameters from which the dataset &amp;quot;Nodes&amp;quot; is calculated)--Kguess is a 2 element vector containing these unknown parameters   &lt;/p&gt;
&lt;p&gt;&amp;gt; f := Vector(n); for i to n do f[i] := evalf(1/sqrt(((Kguess[1]-K[i, 1])/A[na])^2+((Kguess[2]-K[i, 2])/Pe[nPe])^2+1)) end do; &lt;/p&gt;
&lt;p&gt;&amp;gt; ROM := evalf(Phi.C.f);  &amp;gt; ObjectiveFunction := Vector(nn); for i to nn do ObjectiveFunction[i] := evalf((Nodes[i]-ROM[i])/Nodes[i]) end do;  &lt;/p&gt;
&lt;p&gt;&amp;gt; p := proc (Kguess) evalf(add(ObjectiveFunction[i], i = 1 .. nn)/nn) end proc;  &lt;/p&gt;
&lt;p&gt;&amp;gt; Optimization[NLPSolve](2, p, assume = nonnegative);  &lt;/p&gt;
&lt;p&gt;Error, (in Optimization:-NLPSolve) non-numeric result encountered    &lt;/p&gt;
&lt;p&gt;Let me know if there's some newbish mistake that I've made. :)&lt;/p&gt;</description>
      <guid>64473</guid>
      <pubDate>Thu, 06 Aug 2009 08:31:04 Z</pubDate>
      <itunes:author>petrivka</itunes:author>
      <author>petrivka</author>
    </item>
    <item>
      <title>Some Progress</title>
      <link>http://www.mapleprimes.com/questions/36929-Help-With-An-Optimization-Problem-Using-NLPSolve?ref=Feed:MaplePrimes:Help with an Optimization Problem using NLPSolve:Comments#answer64475</link>
      <itunes:summary>&lt;p&gt;Acer,&lt;/p&gt;
&lt;p&gt;You're right about the procedure problem. I was trying to follow the examples in the help files as closely as I could, and that led to doing things in a more complicated way than necessary. So, I tried to put the objective function directly into NLPSolve as you suggested, along with the constraint that the objective function should not exceed 0.05, and this is the result:&lt;/p&gt;
&lt;p&gt;&amp;gt; Optimization:-NLPSolve(add(ObjectiveFunction[i], i = 1 .. nn)/nn, add(ObjectiveFunction[i], i = 1 .. nn)/nn &amp;lt;= 0.5e-1, assume = nonnegative);&lt;br /&gt;
&lt;b&gt;Error, (in Optimization:-NLPSolve) unexpected parameters: Lots of stuff containing Kguess[1] and Kguess[2]&lt;/b&gt;&lt;/p&gt;
&lt;p&gt;I can't seem to convince NLPSolve that Kguess[1] and Kguess[2] &lt;i&gt;are&lt;/i&gt; the parameters to be expected, and that they are the variables to be changed to meet the constraint I specified. I even tried constructing the matrix ROM within NLPSolve from Phi, C, and f, and I get the same result, except with a much longer computation time before the error.&lt;/p&gt;
&lt;p&gt;Sorry if this problem seems elementary, but I do appreciate your help in resolving this issue.&lt;/p&gt;</itunes:summary>
      <description>&lt;p&gt;Acer,&lt;/p&gt;
&lt;p&gt;You're right about the procedure problem. I was trying to follow the examples in the help files as closely as I could, and that led to doing things in a more complicated way than necessary. So, I tried to put the objective function directly into NLPSolve as you suggested, along with the constraint that the objective function should not exceed 0.05, and this is the result:&lt;/p&gt;
&lt;p&gt;&amp;gt; Optimization:-NLPSolve(add(ObjectiveFunction[i], i = 1 .. nn)/nn, add(ObjectiveFunction[i], i = 1 .. nn)/nn &amp;lt;= 0.5e-1, assume = nonnegative);&lt;br /&gt;
&lt;b&gt;Error, (in Optimization:-NLPSolve) unexpected parameters: Lots of stuff containing Kguess[1] and Kguess[2]&lt;/b&gt;&lt;/p&gt;
&lt;p&gt;I can't seem to convince NLPSolve that Kguess[1] and Kguess[2] &lt;i&gt;are&lt;/i&gt; the parameters to be expected, and that they are the variables to be changed to meet the constraint I specified. I even tried constructing the matrix ROM within NLPSolve from Phi, C, and f, and I get the same result, except with a much longer computation time before the error.&lt;/p&gt;
&lt;p&gt;Sorry if this problem seems elementary, but I do appreciate your help in resolving this issue.&lt;/p&gt;</description>
      <guid>64475</guid>
      <pubDate>Thu, 06 Aug 2009 21:03:43 Z</pubDate>
      <itunes:author>petrivka</itunes:author>
      <author>petrivka</author>
    </item>
    <item>
      <title>comments</title>
      <link>http://www.mapleprimes.com/questions/36929-Help-With-An-Optimization-Problem-Using-NLPSolve?ref=Feed:MaplePrimes:Help with an Optimization Problem using NLPSolve:Comments#answer64477</link>
      <itunes:summary>&lt;p&gt;A few minor comments on efficiency:&lt;/p&gt;
&lt;p&gt;Rather than pass the very same add() invocation in two different arguments to NLPSolve, you might try assigning the result of the add() to a variable beforehand, and then passing that assigned variable. (add does not have &lt;i&gt;option remember&lt;/i&gt;, AFAIK, so it is unnecessary duplication to have the same addition get computed more than once.)&lt;/p&gt;
&lt;p&gt;This next may only matter if your numeric Matrices are &lt;i&gt;very&lt;/i&gt; large. Take the Phi.C.f computation, and look at the number of arithmetic operations done. If Phi and C are Matrices and f is a Vector then if can make a measurable difference in performance if you compute Phi.(C.f) instead of (Phi.C).f.&lt;/p&gt;</itunes:summary>
      <description>&lt;p&gt;A few minor comments on efficiency:&lt;/p&gt;
&lt;p&gt;Rather than pass the very same add() invocation in two different arguments to NLPSolve, you might try assigning the result of the add() to a variable beforehand, and then passing that assigned variable. (add does not have &lt;i&gt;option remember&lt;/i&gt;, AFAIK, so it is unnecessary duplication to have the same addition get computed more than once.)&lt;/p&gt;
&lt;p&gt;This next may only matter if your numeric Matrices are &lt;i&gt;very&lt;/i&gt; large. Take the Phi.C.f computation, and look at the number of arithmetic operations done. If Phi and C are Matrices and f is a Vector then if can make a measurable difference in performance if you compute Phi.(C.f) instead of (Phi.C).f.&lt;/p&gt;</description>
      <guid>64477</guid>
      <pubDate>Thu, 06 Aug 2009 23:35:00 Z</pubDate>
      <itunes:author>pagan</itunes:author>
      <author>pagan</author>
    </item>
    <item>
      <title>Thank you both for your help</title>
      <link>http://www.mapleprimes.com/questions/36929-Help-With-An-Optimization-Problem-Using-NLPSolve?ref=Feed:MaplePrimes:Help with an Optimization Problem using NLPSolve:Comments#answer64478</link>
      <itunes:summary>&lt;p&gt;Thank you both for your help so far. That was a good call, pagan, on the unnecessary computations I was introducing. It looks like I'm getting closer to actually solving for the variables Kguess[1] and Kguess[2], but I'm running into this new issue, as follows:&lt;/p&gt;
&lt;p&gt;&amp;gt; errorfunc := Vector(nn); for i to nn do errorfunc[i] := evalf((Nodes[i]-ROM[i])/Nodes[i]) end do;&lt;br /&gt;
&amp;gt; ObjectiveFunction := add(errorfunc[i], i = 1 .. nn)/nn;&lt;br /&gt;
&amp;gt; Optimization:-NLPSolve(ObjectiveFunction, {ObjectiveFunction &amp;gt;= -.20, ObjectiveFunction &amp;lt;= .20});&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Error, (in Optimization:-NLPSolve) no improved point could be found&lt;br /&gt;
&lt;/b&gt;&lt;/p&gt;
&lt;p&gt;Now, I know what the values of Kguess[1] and Kguess[2] should be, and when I input these values manually into the vector f and execute the ObjectiveFunction, I get a value of 0.15, which should satisfy the constraints that I had added to NLPSolve.&lt;/p&gt;
&lt;p&gt;Also, I tried adding in bounds for Kguess[1] and Kguess[2] with the following code:&lt;/p&gt;
&lt;p&gt;&amp;gt; bl := &amp;lt;A[1], Pe[1]&amp;gt;;&lt;br /&gt;
&amp;gt; bu := &amp;lt;A[na], Pe[nPe]&amp;gt;;&lt;br /&gt;
&amp;gt; Optimization:-NLPSolve(ObjectiveFunction, [ObjectiveFunction &amp;lt;= .20, ObjectiveFunction &amp;gt;= -.20], [bl, bu]);&lt;br /&gt;
&lt;b&gt;Error, (in Optimization:-NLPSolve) unexpected parameters: [Vector(2, {(1) = 1/5, (2) = 3000}), Vector(2, {(1) = 2, (2) = 30000})]&lt;br /&gt;
&lt;/b&gt;&lt;/p&gt;
&lt;p&gt;Thank you for your patience and assistance!&lt;/p&gt;</itunes:summary>
      <description>&lt;p&gt;Thank you both for your help so far. That was a good call, pagan, on the unnecessary computations I was introducing. It looks like I'm getting closer to actually solving for the variables Kguess[1] and Kguess[2], but I'm running into this new issue, as follows:&lt;/p&gt;
&lt;p&gt;&amp;gt; errorfunc := Vector(nn); for i to nn do errorfunc[i] := evalf((Nodes[i]-ROM[i])/Nodes[i]) end do;&lt;br /&gt;
&amp;gt; ObjectiveFunction := add(errorfunc[i], i = 1 .. nn)/nn;&lt;br /&gt;
&amp;gt; Optimization:-NLPSolve(ObjectiveFunction, {ObjectiveFunction &amp;gt;= -.20, ObjectiveFunction &amp;lt;= .20});&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Error, (in Optimization:-NLPSolve) no improved point could be found&lt;br /&gt;
&lt;/b&gt;&lt;/p&gt;
&lt;p&gt;Now, I know what the values of Kguess[1] and Kguess[2] should be, and when I input these values manually into the vector f and execute the ObjectiveFunction, I get a value of 0.15, which should satisfy the constraints that I had added to NLPSolve.&lt;/p&gt;
&lt;p&gt;Also, I tried adding in bounds for Kguess[1] and Kguess[2] with the following code:&lt;/p&gt;
&lt;p&gt;&amp;gt; bl := &amp;lt;A[1], Pe[1]&amp;gt;;&lt;br /&gt;
&amp;gt; bu := &amp;lt;A[na], Pe[nPe]&amp;gt;;&lt;br /&gt;
&amp;gt; Optimization:-NLPSolve(ObjectiveFunction, [ObjectiveFunction &amp;lt;= .20, ObjectiveFunction &amp;gt;= -.20], [bl, bu]);&lt;br /&gt;
&lt;b&gt;Error, (in Optimization:-NLPSolve) unexpected parameters: [Vector(2, {(1) = 1/5, (2) = 3000}), Vector(2, {(1) = 2, (2) = 30000})]&lt;br /&gt;
&lt;/b&gt;&lt;/p&gt;
&lt;p&gt;Thank you for your patience and assistance!&lt;/p&gt;</description>
      <guid>64478</guid>
      <pubDate>Fri, 07 Aug 2009 00:24:42 Z</pubDate>
      <itunes:author>petrivka</itunes:author>
      <author>petrivka</author>
    </item>
    <item>
      <title>ah</title>
      <link>http://www.mapleprimes.com/questions/36929-Help-With-An-Optimization-Problem-Using-NLPSolve?ref=Feed:MaplePrimes:Help with an Optimization Problem using NLPSolve:Comments#comment64474</link>
      <itunes:summary>&lt;p&gt;I see. The problem is in the creation of procedure p.&lt;/p&gt;
&lt;p&gt;Consider the following example. Here, the formal parameter x of procedure p is not the same as the x in F.&lt;/p&gt;
&lt;pre&gt;
&amp;gt; F := x:
&amp;gt; p := proc(x) F; end proc:
&amp;gt; p(1);
                                       x
&amp;gt; x:=17:
&amp;gt; p(1);
                                      17
&lt;/pre&gt;
&lt;p&gt;Sometimes, a way to get the intended effect is to use unapply to create the procedure. But for your code you'd want to somehow &amp;quot;unapply&amp;quot; w.r.t the Kguess[i] so that the formal parameter was Kguess (to be passed as a Vector). Which is awkward. Another way might be to create the proc with the &lt;b&gt;add&lt;/b&gt; call, etc, in its body.&lt;/p&gt;
&lt;p&gt;But maybe it can be easier still. Do you really need to use the &amp;quot;operator form&amp;quot; in calling NLPSolve? Could you instead call it with the objective in &amp;quot;expresion form&amp;quot;? The expression would be the result of the &lt;b&gt;add&lt;/b&gt; call. Ie,&lt;/p&gt;
&lt;pre&gt;
Optimization:-NLPSolve(
   add(ObjectiveFunction[i], i = 1 .. nn)/nn,
   assume = nonnegative);
&lt;/pre&gt;
&lt;p&gt;acer&lt;/p&gt;</itunes:summary>
      <description>&lt;p&gt;I see. The problem is in the creation of procedure p.&lt;/p&gt;
&lt;p&gt;Consider the following example. Here, the formal parameter x of procedure p is not the same as the x in F.&lt;/p&gt;
&lt;pre&gt;
&amp;gt; F := x:
&amp;gt; p := proc(x) F; end proc:
&amp;gt; p(1);
                                       x
&amp;gt; x:=17:
&amp;gt; p(1);
                                      17
&lt;/pre&gt;
&lt;p&gt;Sometimes, a way to get the intended effect is to use unapply to create the procedure. But for your code you'd want to somehow &amp;quot;unapply&amp;quot; w.r.t the Kguess[i] so that the formal parameter was Kguess (to be passed as a Vector). Which is awkward. Another way might be to create the proc with the &lt;b&gt;add&lt;/b&gt; call, etc, in its body.&lt;/p&gt;
&lt;p&gt;But maybe it can be easier still. Do you really need to use the &amp;quot;operator form&amp;quot; in calling NLPSolve? Could you instead call it with the objective in &amp;quot;expresion form&amp;quot;? The expression would be the result of the &lt;b&gt;add&lt;/b&gt; call. Ie,&lt;/p&gt;
&lt;pre&gt;
Optimization:-NLPSolve(
   add(ObjectiveFunction[i], i = 1 .. nn)/nn,
   assume = nonnegative);
&lt;/pre&gt;
&lt;p&gt;acer&lt;/p&gt;</description>
      <guid>64474</guid>
      <pubDate>Thu, 06 Aug 2009 10:36:13 Z</pubDate>
      <itunes:author>acer</itunes:author>
      <author>acer</author>
    </item>
  </channel>
</rss>