MathGroup Archive 2011

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

Search the Archive

NMaximize inconsistency

  • To: mathgroup at smc.vnet.net
  • Subject: [mg118617] NMaximize inconsistency
  • From: Jingjing Wang <brightapple2008 at gmail.com>
  • Date: Wed, 4 May 2011 19:46:41 -0400 (EDT)

Dear Group,

I wrote an example to test NMaximize for solving optimization problem
with many constraints. Here are the results when I first run it:

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
T = 3;

a = Table[x[t], {t, T}]
b = Table[y[t], {t, T}]

{x[1], x[2], x[3]}

{y[1], y[2], y[3]}

NMaximize[{Sum[x[t]^2 - y[t], {t, T}],
  Table[x[t] == x[t - 1]^2 + 2 y[t - 1], {t, T}],
  Table[y[t] == x[t] + x[t + 1], {t, T - 1}], x[0] == 1, y[0] == 1},
 Join[a, b]]

{38465.7, {x[1] -> 3., x[2] -> -15., x[3] -> -195., y[1] -> -12.,
  y[2] -> -210., y[3] -> 15.3005}}

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

But when I tried to run it the next day, NMaixmize doesn't work....

>>>>>>>>>>>>>>>>>>>>>>>>

In[191]:= T = 3;

In[192]:= a = Table[x[t], {t, T}]
b = Table[y[t], {t, T}]

Out[192]= {x[1], x[2], x[3]}

Out[193]= {y[1], y[2], y[3]}

In[194]:= NMaximize[{Sum[x[t]^2 - y[t], {t, T}],
  Table[x[t] == x[t - 1]^2 + 2 y[t - 1], {t, T}],
  Table[y[t] == x[t] + x[t + 1], {t, T - 1}], x[0] == 1, y[0] == 1},
 Join[a, b]]

During evaluation of In[194]:= NMaximize::bcons: The following
constraints are not valid: {x[0]==1,y[0]==1,x[0]^2+2
y[0]==x[1],y[1]==x[1]+x[2],x[1]^2+2
y[1]==x[2],y[2]==x[2]+x[3],x[2]^2+2 y[2]==x[3]}. Constraints should be
equalities, inequalities, or domain specifications involving the
variables. >>

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

 Any idea why?

Thanks!-JJ


  • Prev by Date: Re: envelope of curves
  • Next by Date: Re: Bad design in Set?
  • Previous by thread: Re: for cicle inside an If condition
  • Next by thread: how to apply Position repeatedly without a loop?