Register to reply 
I need a method to calculate ln(x) for small x, other than Taylor series method 
Share this thread: 
#1
Jan2611, 04:43 AM

P: 58

I'm aiming to calculate ln(x) numerically. I'm using the following procedure for this:
1) If x is greater or equal to 1, use Newton's method. 2) If x is smaller between 0 and 1, use Taylor series expansion. Newton's method works good, but I have problems with Taylor series expansion method. [itex]\ln(1+x)=\sum_{n=1}^\infty \frac{(1)^{n+1}}{n} x^n = x  \frac{x^2}{2} + \frac{x^3}{3}  \cdots \quad{\rm for}\quad \leftx\right \leq 1\quad[/itex] Sum of this series is [itex]\small \infty\normalsize[/itex] for [itex]\small x=1\normalsize[/itex], but when you try to take sum of it using a computer, it doesn't converge because of computing limitations (like using truncated series). I can't either use Newton's method for this interval, because it has a bad performance for small x values (neither it converges for small x). For x=0.000001; ln(x) = 13.8155... (actual) ln(x) = 1.71828... (calculated) (The summation goes on until absolute value of any element of the series is below a user defined [itex]\epsilon[/itex] value, which is equal to [itex]1.0 \times 10^{14}[/itex] for this particular example.) I need a third method to calculate ln(x) for small x argument. Can you please suggest me one? 


#2
Jan2611, 07:40 AM

P: 85

Maybe you could try directly evaluating the integral:
[tex]\int^{x}_{1}\frac{1}{x}dx[/tex] 


#3
Jan2611, 02:09 PM

HW Helper
P: 925




#4
Jan2611, 02:12 PM

P: 58

I need a method to calculate ln(x) for small x, other than Taylor series method



#5
Jan2611, 03:00 PM

PF Gold
P: 864

[tex]x,\ \frac{x^2}{2},\ \frac{x^3}{2*3},\ \frac{x^4}{2*3*4} ...[/tex] 


#6
Jan2611, 03:05 PM

PF Gold
P: 864

Actually, I'm very sure that's the mistake you made since you got
[tex]e^{(0.0000011)}  1\approx e1\approx 1.7182818...[/tex] 


#7
Jan2611, 03:11 PM

P: 58

The denominator term was was also accumulating into multiplication, so it was becoming factorial of the current for loop variable. It was calculating exp() instead of ln(), what an exciting coincidence... 


#8
Jan2611, 03:13 PM

P: 58

My new code is:



#9
Jan2611, 03:13 PM

Engineering
Sci Advisor
HW Helper
Thanks
P: 6,931

When 0 < x < 1, you could use
ln(x) = ln(1/x) 


#10
Jan2611, 03:15 PM

P: 58

This way I can always use Newton's method, it is better since it converges super fast. Thanks a lot! 


#11
Jan2611, 03:27 PM

P: 58

For example, suppose that you want to calculate ln(0.000001) You send it into Newton's algorithm in this form ln(1000000) I need to calculate exp(1000000) inside the Newton's algorithm, but obviously it is not possible because of the hardware and software limitations. And I also realized that, with this code, there is a very low limit for the argument of ln(). I need to work around this problem. 


#12
Jan2611, 03:46 PM

PF Gold
P: 864

[tex]\ln{(a\cdot 10^{n})}=\ln{a}+n\ln{10}[/tex] 


#13
Jan2611, 04:40 PM

HW Helper
P: 925

Hmmm, I must be missing something. I had no problem at all finding ln(0.000001) using hkBattousai's algorithm for Newton's method. It reduces to x_{k+1} = x_{k}  1 + arg/exp(x_{k}).



Register to reply 
Related Discussions  
Taylor Series Method Integral  Calculus & Beyond Homework  3  
Taylor method for IVPs  Differential Equations  2  
Expanding a small oscillation potential in taylor series  Classical Physics  2  
What method to calculate intergration?  Calculus  4  
Taylor Series Starting Method  Calculus & Beyond Homework  2 