Your situation got me thinking back to my old math days, Jason. When
complaining why we had to learn how to estimate logarithms using Taylor
Series, our teacher would remark "what would you do, if the LOG button on
your calculator suddenly quit working?".  Seems rather fitting huh?

Anyway, I was able to find a Taylor Series that gives a "close fit" for a
natural logarithm (LN). Using that series, I wrote a little cfloop that
will, given an input value and a precision variable, use the Taylor Series
to give a close estimate of the Log base 10 of the input value. Check it
out:

<cfset Temp_Var = 0>
<cfloop Index="x" From="1" TO="#variables.Precision_Value#">
 <cfif variables.x EQ 1>
  <cfset Temp_Var = (Input_Variable-1) / (input_variable+1)>
 <cfelse>
  <cfset Temp_Var = variables.Temp_Var + ( 1/(x+(x-1)) * (
(Input_Variable-1)/(Input_Variable+1) )^(x+(x-1)) )>
 </cfif>
 </cfloop>

<cfset Natural_Log_Var = Temp_Var * 2>     <!--- Entire series is multiplied
by 2 --->
<cfset Log_Base_Ten = Temp_Var * 0.4342>    <!--- Multiply natural log by
.4342 to get Log base 10 --->

You've now got the natural log of the input value, as well as the Log base
10.  As you probably know, the Taylor Series is only a close estimation of
the actual value.  The higher your precision value, the closer the
estimation is to the actual value.  With a precision value of 10, i got
precision within 1/1000th of the actual value. Not bad.

Anyway, I hope this helps....even if it doesn't, its been kinda fun :)

Brian
----- Original Message -----
From: "Snyder, Jason" <[EMAIL PROTECTED]>
To: "CF-Talk" <[EMAIL PROTECTED]>
Sent: Wednesday, August 22, 2001 6:30 PM
Subject: Buggy log10 function in CF 5.0


> I wrote a UDF that uses the log10 function and I noticed something was a
bit fishy.  When I isolated the log10 function and fed it 31 it spit out
1.49136169383.  When I fed it 32 it spit out 3.  (I was expecting something
more like 1.50514997832.)  I went to cflib like what was suggested in a
previous message and picked up logN.  At first this was looking better but
then I noticed something fishy once again.  I noticed that when the input
value is 9 on base 10 [logN(9,10)] it returned 9.  My calculator comes up
with 0.95424250943932 which seems much more reasonable.  What can I do short
of using cfx if I need something that can do logarithms?
>
>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Structure your ColdFusion code with Fusebox. Get the official book at 
http://www.fusionauthority.com/bkinfo.cfm
FAQ: http://www.thenetprofits.co.uk/coldfusion/faq
Archives: http://www.mail-archive.com/[email protected]/
Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists

Reply via email to