|
-
Nov 9th, 2006, 03:37 PM
#1
Thread Starter
Addicted Member
Natural log Calculation
In short, how do calculators work out what the natural log of a number is? I have read that the infinite sum:
Code:
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?
Rich
A)bort, R)etry, I)nfluence with large hammer.
Please take a moment to rate useful posts.

-
Nov 9th, 2006, 07:38 PM
#2
Re: Natural log Calculation
-
Nov 10th, 2006, 10:08 AM
#3
Thread Starter
Addicted Member
Re: Natural log Calculation
Thanks, I'll look at the maths later.
Rich
A)bort, R)etry, I)nfluence with large hammer.
Please take a moment to rate useful posts.

-
Nov 12th, 2006, 09:03 AM
#4
Re: Natural log Calculation
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)]
Lottery is a tax on people who are bad at maths
If only mosquitoes sucked fat instead of blood...
To do is to be (Descartes). To be is to do (Sartre). To be do be do (Sinatra)
-
Nov 12th, 2006, 09:11 AM
#5
Thread Starter
Addicted Member
Re: Natural log Calculation
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.
Rich
A)bort, R)etry, I)nfluence with large hammer.
Please take a moment to rate useful posts.

-
Nov 12th, 2006, 11:48 AM
#6
Re: Natural log Calculation
 Originally Posted by Rich2189
 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:
Code:
e ^ (Log(y) * (1 / x))
Or for example the square root of 9 would be:
Code:
e ^ (Log(9) * (1 / 2))
I think some really early calculator worked this way for calculating roots, and it should be accurate enough.
-
Nov 12th, 2006, 12:18 PM
#7
Thread Starter
Addicted Member
Re: Natural log Calculation
 Originally Posted by Comintern
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:
Code:
e ^ (Log(y) * (1 / x))
Or for example the square root of 9 would be:
Code:
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
Rich
A)bort, R)etry, I)nfluence with large hammer.
Please take a moment to rate useful posts.

-
Nov 12th, 2006, 03:01 PM
#8
Re: Natural log Calculation
 Originally Posted by Rich2189
 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
Last edited by krtxmrtz; Nov 12th, 2006 at 03:05 PM.
Lottery is a tax on people who are bad at maths
If only mosquitoes sucked fat instead of blood...
To do is to be (Descartes). To be is to do (Sartre). To be do be do (Sinatra)
-
Nov 12th, 2006, 03:06 PM
#9
Thread Starter
Addicted Member
Re: Natural log Calculation
 Originally Posted by krtxmrtz
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:
{a i} -> Sqrt(A)
As a 0 you can pick any number because the convergence is very fast, for example you pick a i = A. The new terms are calculated as:
a i+1 = (A/a i + a i) / 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
Rich
A)bort, R)etry, I)nfluence with large hammer.
Please take a moment to rate useful posts.

-
Nov 12th, 2006, 03:15 PM
#10
Re: Natural log Calculation
 Originally Posted by Rich2189
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)
Lottery is a tax on people who are bad at maths
If only mosquitoes sucked fat instead of blood...
To do is to be (Descartes). To be is to do (Sartre). To be do be do (Sinatra)
-
Nov 12th, 2006, 03:19 PM
#11
Thread Starter
Addicted Member
Re: Natural log Calculation
 Originally Posted by krtxmrtz
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 .
Rich
A)bort, R)etry, I)nfluence with large hammer.
Please take a moment to rate useful posts.

-
Nov 12th, 2006, 03:26 PM
#12
Re: Natural log Calculation
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?
Lottery is a tax on people who are bad at maths
If only mosquitoes sucked fat instead of blood...
To do is to be (Descartes). To be is to do (Sartre). To be do be do (Sinatra)
-
Nov 12th, 2006, 03:31 PM
#13
Thread Starter
Addicted Member
Re: Natural log Calculation
 Originally Posted by krtxmrtz
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.
Rich
A)bort, R)etry, I)nfluence with large hammer.
Please take a moment to rate useful posts.

-
Nov 12th, 2006, 03:43 PM
#14
Re: Natural log Calculation
 Originally Posted by Rich2189
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.
Lottery is a tax on people who are bad at maths
If only mosquitoes sucked fat instead of blood...
To do is to be (Descartes). To be is to do (Sartre). To be do be do (Sinatra)
-
Nov 12th, 2006, 03:55 PM
#15
Thread Starter
Addicted Member
Re: Natural log Calculation
 Originally Posted by krtxmrtz
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.
Rich
A)bort, R)etry, I)nfluence with large hammer.
Please take a moment to rate useful posts.

Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|