       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,c,c,cem,cem,cem,cpc,cpc,cpc,e,<<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,c,c,cem,cem,cem,cpc,cpc,cpc,e,<<46>>}\
>   = {1.,1.,1.,1.,1.,1.,1.,1.,1.,1.,<<46>>}."

The expressions such as c,c,c,cem, or cem, 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, c, c, cem, ...

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

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

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

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

Now we assign the value 3 to c.

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

Out= {0.0825888, {x -> 0.16374}}

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

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

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

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

In:= % /. c -> 3 // N

Out= {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?