Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: Problem with NMaximize
Replies: 11   Last Post: Jun 28, 2008 5:58 AM

 Messages: [ Previous | Next ]
 Jean-Marc Gulliet Posts: 2,276 Registered: 6/12/05
Re: Problem with NMaximize
Posted: Jun 27, 2008 6:18 AM

Ramiro Barrantes-Reynolds wrote:

<snip>

> {res, data} =
> Reap[NMaximize[{logLikelihood[{{5, 5, 0, 0}, {3, 1, 0, 1}}, {33, 83,
> 11, 14}, S,
> a, {l1, l2, l3, l4}, {t1, t2, t3, t4, t5, t6, t7, t8, t9, t10,
> t11, t12}], l1 > 0, l2 > 0, l3 > 0, l4 > 0, t1 > 0, t2 > 0,
> t3 > 0, t4 > 0, t5 > 0, t6 > 0, t7 > 0, t8 > 0, t9 > 0, t10 > 0,
> t11 > 0, t12 > 0,
> t1 + t2 + t3 + t4 + t5 + t6 + t7 + t8 + t9 + t10 + t11 + t12 ==
> 1}, {a, l1, l2, l3, l4, t1, t2, t3, t4, t5, t6, t7, t8, t9, t10,
> t11, t12},
> EvaluationMonitor :>
> Sow[{a, {l1, l2, l3, l4}, {t1, t2, t3, t4, t5, t6, t7, t8, t9,
> t10, t11, t12}}]]];

The code is not complete since you did not post the definition of the
function logLikelihood[...]

> NMaximize::nrnum: The function value 28.2245-6.28319 I is not a real \
> number at {a,l1,l2,l3,l4,t1,t10,t11,t12,t2,<<7>>} = \
> {1.,2.,2.,<<6>>,0.0799689,<<7>>}. >>

Nevertheless, by reading this above error message I bet that your
function is called with symbolic arguments (i.e. non-numeric arguments).
The following should help to correctly defined your function so it will
be called by NMaximize only when all its arguments are numeric values.

"How do I write a function which evaluates only when the argument is a
number?"

http://support.wolfram.com/mathematica/kernel/features/evalwhennumber.html

Regards,
-- Jean-Marc

Date Subject Author
6/26/08 Ramiro Barrantes-Reynolds
6/27/08 Jean-Marc Gulliet
6/27/08 ramiro
6/27/08 DrMajorBob
6/27/08 DrMajorBob
6/27/08 Jean-Marc Gulliet
6/28/08 mante
6/28/08 Bill Rowe
6/28/08 Daniel Lichtblau