Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2012

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: FindMinimum function does not seem to work for simple problems

  • To: mathgroup at smc.vnet.net
  • Subject: [mg128114] Re: FindMinimum function does not seem to work for simple problems
  • From: Dana DeLouis <dana01 at me.com>
  • Date: Mon, 17 Sep 2012 00:20:08 -0400 (EDT)
  • Delivered-to: l-mathgroup@mail-archive0.wolfram.com
  • Delivered-to: l-mathgroup@wolfram.com
  • Delivered-to: mathgroup-newout@smc.vnet.net
  • Delivered-to: mathgroup-newsend@smc.vnet.net

> Please note that Mathematica 8.0 does not allow you to put a linear constraint with a single variable 
> equated to a constant value (I note that others have reported this bug in forums such as this). 
>  I had to introduce a dummy variable "eps" equated to 1 indirectly to handle this problem.

Hi.  I'm not an expert, but even if it were not a bug, one would be asking the program to work harder than it has to.

FindMinimum[{(x - 1.0)^2 + (y - 2.0)^2, x == 2.0}, {{x, 1.0}, {y, 1.0}}]

What you are asking is that the variable x varies at machine precision, and then figure out how to make x ==2.
What I believe is happing to cause the error has something to do with the gradient at machine precision, but I'm not sure.

I believe it's easier in Mathematica (and more efficient) to just go ahead and use the Constants in the equation.   This eliminates a lot of unnecessary work:

equ = (x - 1)^2 + (y - 2)^2     /. x -> 2
(y - 2)^2 + 1

FindMinimum[equ,{y,1}]
{1.,{y->2.}}

Now, one is only varying y.  No sense in changing x if x is not suppose to change.

For this small example, Minimize works a little better thou:

equ = {(x - 1)^2 + (y - 2)^2, x == 2};

Minimize[equ, {x,y} ]

{1,{x->2,y->2}}


The program likes to work with constraints.  Sometimes, one can see if the constant happens to be on the border via inequalities.

FindMinimum[{(x-1)^2+(y-2)^2,  x<=2}, {x,y}]

{4.44354*10^-13,{x->0.999999,y->2.}}

Ok.  The above didn't work.  Let's try :  x>= 2

FindMinimum[{(x-1)^2+(y-2)^2,x>= 2},  {x,y}]

{1.,{x->2.,y->2.}}

Ok.  That worked   :>)

= = = = = = = = = =
HTH  :>)
Dana DeLouis
Mac & Mathematica 8
= = = = = = = = = =





On Sunday, September 16, 2012 3:24:18 AM UTC-4, Vassilis wrote:
> The problem arises from the discretization of a simple optimal control problem.
> 
> 
> 
> The description is as follows:
> 
> 
> 
> dv/dt = u
> 
> dx/dt = v
> 
> x(0)=0, v(0)=0,
> 
> x(tf)=300, v(tf)=0,
> 
> minimize tf.
> 
> -2<=u<=+1
> 
> 
> 
> The solution for this analytically is 30 time units as the minimum value of tf.
> 
> 
> 
> I used implicit Euler steps (backward finite differences) over a few steps to try to solve it with FindMinimum to test it (before I linked in larger optimal control problems).  The performance is very very poor, unjustifiably so for a code that Wolfram advertise as "industrial strength".  I tested this problem on CONOPT through GAMS and has no problems converging whatsoever for even very large numbers of discretization steps.
> 
> 
> 
> Here is the set of inputs to Mathematica.  Please note that Mathematica 8.0 does not allow you to put a linear constraint with a single variable equated to a constant value (I note that others have reported this bug in forums such as this).  I had to introduce a dummy variable "eps" equated to 1 indirectly to handle this problem.
> 
> 
> 
> === BEGIN MODEL ==================
> 
> 
> 
> nsteps = 13;
> 
> 
> 
> vlist = Table[v[i], {i, 0, nsteps}];
> 
> 
> 
> xlist = Table[x[i], {i, 0, nsteps}];
> 
> 
> 
> hlist = Table[h[i], {i, 1, nsteps}];
> 
> 
> 
> ulist = Table[u[i], {i, 1, nsteps}];
> 
> 
> 
> varslist = Join[vlist, xlist, hlist, ulist, {eps}];
> 
> 
> 
> obj0 = Sum[h[i], {i, 1, nsteps}] + 10.^3*(eps - 1.0)^2;
> 
> 
> 
> odes = Flatten[
> 
>    Table[{x[i] - x[i - 1] == v[i]*h[i],
> 
>      v[i] - v[i - 1] == h[i]*u[i]}, {i, 1, nsteps}]];
> 
> 
> 
> ubounds = Flatten[Table[{u[i] <= 1.0, u[i] >= -2.0}, {i, 1, nsteps}]];
> 
> 
> 
> hbounds = Flatten[Table[{h[i] <= 100.0, h[i] >= 1.0}, {i, 1, nsteps}]];
> 
> 
> 
> (* these boundary conditions have a problem... equality of a single variable to a fixed value does not seem to work with FindMinimum as a valid constraint for some reason *)
> 
> boundary = {x[0]*eps == 0.0, v[0]*eps == 0.0, x[nsteps]*eps == 300.0, v[nsteps]*eps == 0.0} ;
> 
> 
> 
> 
> 
> 
> 
> constr0 =
> 
>   Join[odes, ubounds, hbounds, boundary, {eps <= 1.000001, 0 <= eps}];
> 
> 
> 
> nvars0 = Dimensions[varslist][[1]];
> 
> 
> 
> vars0 = Transpose[{varslist, Table[1.0, {nvars0}]}]; vars0 = Join[Take[vars0, nvars0 - 1], {{eps, 1.0}}];
> 
> 
> 
> {objopt, solopt} = FindMinimum[
> 
>   {obj0, constr0}, vars0, Method -> "InteriorPoint"
> 
>   ]
> 
> 
> 
> === END MODEL ===================
> 
> 
> 
> The output that Mathematica gives after a very long run is the following:
> 
> 
> 
> FindMinimum::eit: The algorithm does not converge to the tolerance of 4.806217383937354`*^-6 in 500 iterations. The best estimated solution, with feasibility residual, KKT residual, or complementary residual of {0.000289013,0.0284091,2.28413*10^-11}, is returned. >>
> 
> 
> 
> I note that CONOPT gives a solution in a fraction of a second, e.g. milliseconds as it is really designed to solve problems with thousands of variables.  If we believe what Wolfram are saying on their introduction to "Contrained Optimization", then the FindMinimum function implements a state-of-the-art Interior Point method and should be able to handle very easily large sparse problems,pretty much like the one I used to test it.
> 
> 
> 
> I note that the problem is essentially linear, were it not for bilinear terms in the equalities.  Although this will give rise to many local solutions (the problem is nonconvex) it should not be hard to solve at all.  This is proven at least by the use of one more commercial large scale solver like CONOPT...
> 
> 
> 
> Any ideas as to how it might be possible to still use FindMinimum are most welcome.  Alternatively, I would be forced to consider how to link a serious solver like IPOPT from the COIN-OR project into Mathematica --- which I'd like to avoid and use totally native routines from Mathematica...
> 
> 
> 
> With sincere regards,
> 
> 
> 
> Vassilis








  • Prev by Date: Re: Regression Testing of Graphics: some questions
  • Next by Date: Re: WebServices and SOAP Messages
  • Previous by thread: Re: FindMinimum function does not seem to work for simple problems
  • Next by thread: Kernel exits