```Date: Jun 26, 2008 4:45 AM
Author: Ramiro Barrantes-Reynolds
Subject: Problem with NMaximize

Hello,I am trying to calculate the maximum likelihood of a logarithmicfunction over 17 parameters.    I am using NMaximize and setting allthe parameters to be over 0, and the sum of the a group of them (t's)to be equal to 1 (i.e.  t1 + t2 + t3 + t4 + t5 + t6 + t7 + t8 + t9 +t10 + t11 + t12 ==  1) (complete code at the end).   My constraintswould then be: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 == 1When I run NMaximize over my function I get:NMaximize::nrnum: "The function value 28.2245-6.28319I is not areal number at {a,l1,l2,l3,l4,t1,t10,t11,t12,t2,<<7>>}={1.,2.,2.,<<6>>,0.0799689,<<7>>}."which is because the number inside the logarithm is negative.  When Iused EvaluationMonitor and looked at the iterations I saw that thefirst iteration was:In[189]:= data[[1, 1]]Out[189]= {1., {2., 2., 2., 2.}, {1.22125*10^-15, 0.,-2.22045*10^-16,  0., -2.22045*10^-16, -2.22045*10^-16,-2.22045*10^-16, -1.11022*10^-16, 1., -2.22045*10^-16, 0., 0.}}As you can see there are several negative numbers, even though theconstraints should enforce otherwise.  The error I get I think is aconsequence of that,In[188]:= data[[1, -1]]Out[188]= {1., {2., 2., 2., 2.}, {t1, 0.0799689, 0.0478029,   0.0263613, 0.0356839, 0.0720513, 0.066108, 0.0861263, 1., 0.0849883,    0.0498477, 0.000577809}}This input would lead to my function evaluating a negative logarithm.However, NMaximize shouldn't be evaluating any negative numbers in theparameters right?Any ideas?Thank you,Ramiro{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}}]]];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>>}. >>
```