Re: indeterminate and infinity expressions
- To: mathgroup at smc.vnet.net
- Subject: [mg67613] Re: indeterminate and infinity expressions
- From: Bill Rowe <readnewsciv at earthlink.net>
- Date: Sun, 2 Jul 2006 06:27:32 -0400 (EDT)
- Sender: owner-wri-mathgroup at wolfram.com
On 7/1/06 at 5:11 AM, merser at image.dk (Søren Merser) wrote: >I need to evaluate the expression below: >In[1]:= Log[(#/yhat)] + (1-#) Log[(1-#)/(1-yhat)] & /@ {0,1} /. >yhat->123 Out[1]= {Indeterminate, -Infinity} >Depending on the value of #, I get Infinity and Inderterminate >results. This makes sense because you are evaluating the expression at 0,1. The first term of the expression when evaluated at 0 reduces to Log[0] which evaluates to -Infinitiy. The second term of the expression when evaluated will reduce to 0 times -Infinity which is indeterminate. >To get the wanted answer I've to split the expression into two parts >In[2]:= ans1 = # Log[#/yhat] & /@ {0, 1} yhat -> .123 >Out[2]= {Indeterminate, 2.09557} >In[3]:= ans2 = (1-#) Log[(1-#)/(1-yhat)] & /@ {0, 1} /. yhat -> .123 >Out[3]= {0.131248, Indeterminate} >In[4]:= Max[#] & /@ ({ans1, ans2} /. Indeterminate -> 0) >Out[4]= {2.09557, 0.131248} >Now, is there an easier way to do it? There are other ways to do the same thing. For example I could do something like In[10]:= List @@ (Log[#1/yhat] + (1 - #1)* Log[(1 - #1)/(1 - yhat)] & )[x] /. yhat -> 0.123 Out[10]= {(1-x) log(1.14025 (1-x)),log(8.13008 x)} followed by In[11]:= Cases[Flatten[MapThread[#1 /. x -> #2 & , {%, {0, 1}}]], _?NumericQ] Out[11]= {0.131248,2.09557} I don't clainm this is simpler, but it does avoid the manual splitting of the expression you did. But I am curious as to what you hope to accomplish since the result certainly isn't the value of the full expression at 0 or 1. -- To reply via email subtract one hundred and four