Calculate Mathematical function 'LOG'

Hi, I need to calculate a value with the ‘LOG’ function. This function is not included in the C/AL code. Does anybody know how to do this ? Thanks in advance Nico

You might be able to pull something from: http://www.neoprogrammics.com/vb/Log10.htm I used this site to write Sin, Cos, etc. for GPS algorithms. -john

You could use excel automation and use worksheetfunction.log(arg) it returns a double

I’m rusty on my math, but isnt LOG a fancy way of doing a POWER? I think it’s something like 2LOG3 is the same as 3 to the power of 1/2. If that’s the case, then you can do POWER(3,1/2). Check out the C/SIDE Reference guide.

Logarithm is not a fancy way of doing a POWER. In fact, logarithm is the inverse function of exponentiation. It is the power that you must raise a base number to achieve a desired result. For example, the base 10 log of 100 is 2 (i.e. you must raise 10 to the 2nd power to get 100). It’s used all the time in math and science applications but I haven’t seen much use in business applications. There was an OCX posted in the download section of www.mibuso.com some time ago that provided access to the trigonometric functions; I don’t remember if logarithm was included or not.

Well excuse me for not using proper mathmatical terminology Jack [:D], but I can remember that logarithms can be notated using power. If 10 to the power of 2 is 100, then 100 to the power of 1/2 (hey, that’s the inverse of the EXPONENT 2, what a coinkydink) is 10, and I believe that works for all of them. I still don’t think you need an OCX, just try POWER(3,1/2), which I still think is the same as 2LOG3. You should be able to verify this with a little test form. Oh, by the way the correct syntax for POWER is: NewNumber := POWER(Number, Power) where NewNumber is the new number [Duh!] Number is the number you want to raise exponentially Power is the exponent in the function. But you can find that in F1 help.

What if I ask for LOG(25) base 10? In other words: what is the number z such that Power(10,z) = 25? It is true that Power(25,1/z) = 10, i.e. you take the z’th root of 25. But you can’t calculate z itself just by using the Power, 25 and 10 (e.g. Power(25,1/10) or Power(10,1/25) is not going to give you z). You could, however, use Power to try guessing z, with some sort of binary search. Since 25 is between Power(10,1) and Power(10,2), its log is between 1 and 2, so starting with 1.5 as my initial guess after eight or nine tries, I get 1.397890625 (I may have a mistake in my calculations), whereas LOG(25) = 1.39794. It’s better than nothing, but I’m sure there are more efficient ways of calculating logs to the same accuracy.

quote:

…You could, however, use Power to try guessing z, with some sort of binary search. Since 25 is between Power(10,1) and Power(10,2), its log is between 1 and 2, so starting with 1.5 as my initial guess after eight or nine tries, I get 1.397890625 (I may have a mistake in my calculations), whereas LOG(25) = 1.39794. It’s better than nothing, but I’m sure there are more efficient ways of calculating logs to the same accuracy.
Originally posted by afarr - 2005 Jan 07 : 14:11:11

I think that a recursive calculation is the only option here…You can either use the method outlined above or steal the code from John’s site above (They work slightly differently, but should get the same results [?]). I think that Alastair’s method is a little more effecient (Believe it or not)

OK then… I created a little form with one button. The code in the OnPush trigger is this: MESSAGE(FORMAT(POWER(25,(1/10)))); The message that pops up says 1.3797296614612, which is the number Allistair is looking for. Now you tell me that is wrong? What is wrong about that?

quote:

The message that pops up says 1.3797296614612, which is the number Allistair is looking for. Now you tell me that is wrong? What is wrong about that?
Originally posted by DenSter - 2005 Jan 10 : 09:14:50

You have managed to calculate the 10th root of 25 which is 1.379… . The base 10 log of 25 is 1.39794… . These are not the same number.

aaaaaahhhhhhhhhh… riiiiiiiiight… power of 1/n is not the n-th based log but the n-th root…[Duh!] See I knew I was rusty on my math, I stand corrected. I am just a little bit embarrassed now [:I]