MathGroup Archive 2008

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

Search the Archive

Re: NMaximize Questions

  • To: mathgroup at smc.vnet.net
  • Subject: [mg90954] Re: NMaximize Questions
  • From: Jean-Marc Gulliet <jeanmarc.gulliet at gmail.com>
  • Date: Thu, 31 Jul 2008 06:03:34 -0400 (EDT)
  • Organization: The Open University, Milton Keynes, UK
  • References: <g6rnra$7j5$1@smc.vnet.net>

Stuart Nettleton wrote:

> Hi, I was wondering if someone might be able to help me with some  
> NMaximize issues? Thanks, Stuart
> 1. Is there any limit to the number of variables in NMaximise. Is it  
> possible/sensible to run a model with about 1,300 variables?
> 2. What is the meaning of the following error?
> Error is:
> NMaximize::nnum: "The function value 0 is not a number at \
> {c[1],c[2],c[3],cem[1],cem[2],cem[3],cpc[1],cpc[2],cpc[3],e[1],<<53>>}\
>   = {0.,2.57857*10^-17,-4.69557*10^-17,0.,<<24>>,<<23>>,<<23>>,3.6165*\
> 10^-21,-6.20768*10^-21,4.81393*10^-13,<<53>>}. "
> 
> The error using FindMaximum is:
> FindMaximum::nrgnum: "The gradient is not a vector of real numbers at \
> {c[1],c[2],c[3],cem[1],cem[2],cem[3],cpc[1],cpc[2],cpc[3],e[1],<<46>>}\
>   = {1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,<<46>>}."

The expressions such as c[1],c[2],c[3],cem[1], or cem[2], do not hold 
any values (and especially no numeric values); therefore they evaluate 
to themselves (as symbolic expressions). NMaximize an FinMaximum use 
numeric algorithms to find numeric solutions, thus they required -- and 
can handle only -- numeric values. Therefore, you must provide numeric 
values to *all* the parameters such as c[1], c[2], c[3], cem[1], ...

For instance, say we want to maximize the function -x^4 - c[1] x^2 + x.
Below, the coefficient c[1] does not hold any value but itself.

In[1]:= NMaximize[-x^4 - c[1] x^2 + x, x]

During evaluation of In[1]:= NMaximize::nnum: The function value
-0.296289+0.0929857 c[1] is not a number at {x} = {0.304936}.

Out[1]= NMaximize[x - x^4 - x^2 c[1], x]

Now we assign the value 3 to c[1].

In[2]:= c[1] = 3;
NMaximize[-x^4 - c[1] x^2 + x, x]

Out[3]= {0.0825888, {x -> 0.16374}}

Note that *Maximize* has no problem dealing with symbolic coefficients.

In[4]:= c[1] =. (* Clear c[1] *)
Maximize[-x^4 - c[1] x^2 + x, x]

Out[5]= {-Root[
    27 + 4 c[1]^3 + (144 c[1] + 16 c[1]^4) #1 + 128 c[1]^2 #1^2 +
      256 #1^3 &, 1], {x ->
    Root[-Root[
         27 + 4 c[1]^3 + (144 c[1] + 16 c[1]^4) #1 + 128 c[1]^2 #1^2 +
           256 #1^3 &, 1] - #1 + c[1] #1^2 + #1^4 &, 1]}}

If we replace c[1] by 3 in the above symbolic solution, we get the same 
answer as the one found by numerical algorithm.

In[6]:= % /. c[1] -> 3 // N

Out[6]= {0.0825888, {x -> 0.16374}}

Regards,
-- Jean-Marc


  • Prev by Date: Re: When is a List not a List?
  • Previous by thread: NMaximize Questions
  • Next by thread: rotate axes labels with Plot3D?