Click to See Complete Forum and Search --> : Natural log Calculation
Rich2189
Nov 9th, 2006, 02:37 PM
In short, how do calculators work out what the natural log of a number is? I have read that the infinite sum:
ln(1+x) = x - x^2/2 + x^3/3 - x^4/4 + x^5/5 - x^6/6 + ...
Will produce the answer. It does but if the number is higher than 1000 the accuracy is rubbish, even if the infinite sum is calculated to its 70000th iteration.
So how does the common scientific calculator do it to such a good accuracy and so fast?
Comintern
Nov 9th, 2006, 06:38 PM
Check out this link (http://www.hpmuseum.org/journals/9100iprg.htm) .
Rich2189
Nov 10th, 2006, 09:08 AM
Thanks, I'll look at the maths later.
krtxmrtz
Nov 12th, 2006, 08:03 AM
The formula holds only for
-1 < x <= 1
Therefore when x is out of this range you decompose it.
If v = y*10w then,
ln v = ln y + w ln 10
and then you use the formula for v. For example:
ln 7777 = ln 0.7777 + 4*ln 10
and now use the formula:
ln 0.7777 = ln [1 + (-0.2223)]
Rich2189
Nov 12th, 2006, 08:11 AM
:) thanks for the explaination, I needed it :). Could you please explain the square root one? All I can gather is that it is a sum of a sequence. The reason for this question is i'm trying to make a calculator that is accurate to
1000 numbers.
Comintern
Nov 12th, 2006, 10:48 AM
:) thanks for the explaination, I needed it :). Could you please explain the square root one? All I can gather is that it is a sum of a sequence. The reason for this question is i'm trying to make a calculator that is accurate to
1000 numbers.
If you're looking for that type of precision in a calculator, the fastest way I can think of it to store e (2.71828182845905...) to 1000 digits and use that to calculate bases with. Since you already have an algorithm for logs, you can use this to calculate arbitrary roots. The x root of y can be expressed like this:
e ^ (Log(y) * (1 / x))
Or for example the square root of 9 would be:
e ^ (Log(9) * (1 / 2))
I think some really early calculator worked this way for calculating roots, and it should be accurate enough.
Rich2189
Nov 12th, 2006, 11:18 AM
If you're looking for that type of precision in a calculator, the fastest way I can think of it to store e (2.71828182845905...) to 1000 digits and use that to calculate bases with. Since you already have an algorithm for logs, you can use this to calculate arbitrary roots. The x root of y can be expressed like this:
e ^ (Log(y) * (1 / x))
Or for example the square root of 9 would be:
e ^ (Log(9) * (1 / 2))
I think some really early calculator worked this way for calculating roots, and it should be accurate enough.
But in order to store e to that many places i must first make my big Number class. Which raises the question how do you perform ^ operations, on numbers that large when neither of the numbers are integers:
2.71828182845905.............^some disgusting decimal. :) I need to sit down and have a serious think about this. Everything is going round in circles. IN addition to that I'm storing everything in base 256 :confused: :eek2: :eek2:
krtxmrtz
Nov 12th, 2006, 02:01 PM
:) thanks for the explaination, I needed it :). Could you please explain the square root one? All I can gather is that it is a sum of a sequence. The reason for this question is i'm trying to make a calculator that is accurate to
1000 numbers.
Accurate to 1000 numbers??? That's beyond the power of my magic wand :)
The use of logs is probably to best way to go to calculate a square root. However, a different way to calculate is using a sequence:
{ai} -> Sqrt(A)
As a0 you can pick any number because the convergence is very fast, for example you pick ai = A. The new terms are calculated as:
ai+1 = (A/ai + ai) / 2
This is called the Newton-Raphson method, you can read about it in zillions of web sites, for example:
http://mathworld.wolfram.com/NewtonsMethod.html
Rich2189
Nov 12th, 2006, 02:06 PM
Accurate to 1000 numbers??? That's beyond the power of my magic wand :)
The use of logs is probably to best way to go to calculate a square root. However, a different way to calculate is using a sequence:
{ai} -> Sqrt(A)
As a0 you can pick any number because the convergence is very fast, for example you pick ai = A. The new terms are calculated as:
ai+1 = (A/ai + ai) / 2
Thanks guys :), 1000 decimal places is too much of a challenge then, well i'll try for something more realistic like 200. Ill sit down with a piece(lots of) paper and work through some of this stuff.
Also, would you have any idea how to work out something like this via an algorithm?
4.6^5.83
krtxmrtz
Nov 12th, 2006, 02:15 PM
Thanks guys :), 1000 decimal places is too much of a challenge then, well i'll try for something more realistic like 200. Ill sit down with a piece(lots of) paper and work through some of this stuff.
Also, would you have any idea how to work out something like this via an algorithm?
4.6^5.83
200? Well, handheld calculators give you just 9 or 10 decimal places, that should be enough for mostly everything... or are you trying to send your own rocket to the Moon or something?
Also in computers floating point values give you just a few digits of accuracy, usually less than 20.
4.65.83 = 105.83 log(4.6)
Rich2189
Nov 12th, 2006, 02:19 PM
200? Well, handheld calculators give you just 9 or 10 decimal places, that should be enough for mostly everything... or are you trying to send your own rocket to the Moon or something?
Also in computers floating point values give you just a few digits of accuracy, usually less than 20.
4.65.83 = 105.83 log(4.6)
:) I just want to best Microsofts Calculator. Plus I don't like seeing
1.9382938x10^99
there is no way all the other numbers are 0. What would you suggest a realistic value was? 30? then move into x10^.....?
4.65.83 = 105.83 log(4.6) Thanks on 2 accounts, didn't know about the [sup ] tag and yet another use for logs :).
krtxmrtz
Nov 12th, 2006, 02:26 PM
What is it you exactly want to do? Be accurate to the 200th decimal place? Or work with large numbers beyond the range of 1099?
Rich2189
Nov 12th, 2006, 02:31 PM
What is it you exactly want to do? Be accurate to the 200th decimal place? Or work with large numbers beyond the range of 1099?
Well initially I had thoughts of working with numbers accurate to 200 d.p but it seems that is pointless and not needed. So working with numbers beyond 1099 would be my current aim. so 20/30 decimal places of accuracy with and exponent of upto 101000.
krtxmrtz
Nov 12th, 2006, 02:43 PM
Well initially I had thoughts of working with numbers accurate to 200 d.p but it seems that is pointless and not needed. So working with numbers beyond 1099 would be my current aim. so 20/30 decimal places of accuracy with and exponent of upto 101000.
If you're going to work with integers only, then it shouldn't be too difficult, but I never went into something like this.
Good luck anyway.
Rich2189
Nov 12th, 2006, 02:55 PM
If you're going to work with integers only, then it shouldn't be too difficult, but I never went into something like this.
Good luck anyway.
It's including decimals :). Thank-you both for all the advice, if I manage to get it sorted I'll send you a link.
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.