common problem with FindMinimum and NIntegrate

*To*: mathgroup at smc.vnet.net*Subject*: [mg69505] common problem with FindMinimum and NIntegrate*From*: wtplasar at ehu.es*Date*: Thu, 14 Sep 2006 06:56:13 -0400 (EDT)

Hi everyone, Some people have enquired in the past about how to avoid error messages similar to this one I get: NMinimize::nnum: The function value Experimental`NumericalFunction[{Hold[bestchi[om, ol]], Block}, <<4>>, {None, None}] is not a number at {ol, om} = {1.5636149496419025`,0.08724393316032257`} I have read the documentation and tried to implement the recommendations posted at mathgroup, but to no avail. Here is my code (it won't take much from your time): ndat = {1.`, 2.`, 3.`, 4.`, 5.`, 6.`, 7.`, 8.`, 9.`}; Hobs = {69.`, 83.`, 70.`, 87.`, 117.`, 168.`, 177.`, 140.`, 202.`}; sH = {12.`, 8.3`, 14.`, 17.4`, 23.4`, 13.4`, 14.2`, 13.5`, 40.4`}; H[x_, om_, ol_, H0_] := H0 Sqrt[om (1 + x)^3 + ol + (1 - om - ol)(1 + x)^2]; Hlist[om_, ol_, H0_, mylist_] := Thread[H[#, om, ol, H0]] &[mylist]; chisq[om_?NumericQ, ol_?NumericQ, H0_? NumericQ] := Switch[Head[N[#]], Real, #, Complex, 10^20] &[Module [{vec1 = (Hobs - Hlist[om, ol, H0, z])^2, vec2 = (sH^2)}, Total [vec1/vec2]]]; bestchi[om_?NumericQ, ol_?NumericQ] := -2*Log[NIntegrate[1/(3 Sqrt[2 Pi])Exp[- Chop[(H0 - 73)]^2/18]Exp[-chisq[om, ol, H0]/2], {H0, 71, 75}, WorkingPrecision -> 20]]; NMinimize[{bestchi[om, ol], 0.7 > om > 0 && ol > 0}, { om, ol}, Method -> {"RandomSearch"}]; I would appreciate someone posted a reply to show me how to fix it. Thanks a lot in advance, Ruth Lazkoz