views:

640

answers:

7

I'm trying to use Taylor series to develop a numerically sound algorithm for solving a function. I've been at it for quite a while, but haven't had any luck yet. I'm not sure what I'm doing wrong.

The function is

f(x)=1 + x - sin(x)/ln(1+x)   x~0

Also: why does loss of precision even occur in this function? when x is close to zero, sin(x)/ln(1+x) isn't even close to being the same number as x. I don't see where significance is even being lost.

In order to solve this, I believe that I will need to use the Taylor expansions for sin(x) and ln(1+x), which are

x - x^3/3! + x^5/5! - x^7/7! + ...

and

x - x^2/2 + x^3/3 - x^4/4 + ...

respectfully. I have attempted to use like denominators to combine the x and sin(x)/ln(1+x) components, and even to combine all three, but nothing seems to work out correctly in the end. Any help is appreciated.

A: 

Hi, I haven't looked into this that closely, but you should be aware that some taylor series converge very, very slowly.

Steve
A: 

As this is homework, I'm just going to try to give a few pointers in the right direction.

Solution 1

Rather than using the Talyor series approximation, try to simply use a root finding algorithm such as the Newton-Raphson method, linear interpolation, or interval bisection (or combine them even). They are very simple to implement, and with an appropiate choice of starting value(s), the root can converge to a precise value quite quickly.

Solution 2

If you really need to use the Taylor series approximation for whatever reason, then just expand the sin(x), ln(x), and whatever else. (Multiplying through by ln(x) to remove the denominator in your case will work). Then you'll need to use some sort of polynomial equation solver. If you want a reasonable degree of accuracy, you'll need to go beyond the 3rd or 4th powers I'd imagine, which means a simple analytical solution is not going to be easy. However, you may want to look into something like the Durand-Kerner method for solving general polynomials of any order. Still, if you need to use high-order terms this approach is just going to lead to complications, so I would definitely recommend solution 1.

Hope that helps...

Noldorin
A: 

Just compute the Taylor series of f directly.

Maxima gives me (first 4 terms about x=0):

(%i1) f(x):=1 + x - sin(x)/log(1+x);
                                           - sin(x)
(%o1)                     f(x) := 1 + x + ----------
                                          log(1 + x)


(%i2) taylor(f(x),x,0,4);
                                2    3    4
                           x   x    x    x
(%o2)/T/                   - + -- + -- + --- + . . .
                           2   4    24   240
timday
+1  A: 

I think you need to look at what happens to ln(x+1) as x -->0 and you will see why this function does not behave well near x = 0.

Mark Lavin
+2  A: 

The loss of precision can come in because when x ~ 0, ln(1+x) is also close to 0, so you wind up dividing by a very small number. Computers aren't very good at that ;-)

If you use the Taylor series for ln(1+x) directly, it's going to be kind of a pain because you'll wind up dividing by an infinite series of terms. For cases like this, I usually prefer to just compute the Taylor series for the entire function as a whole from the definition:

f(x) = f(0) + f'(0) x + f''(0) x/2 + f'''(0) x/6 + ...

from which you'll get

f(x) = 2 + 3x/2 - x^2/4 - x^3/24 - x^4/240 - 23x^5/1440 + 31x^6/2880 ...

(I cheated and plugged it into Mathematica ;-) Like Steve says, this series doesn't converge all that quickly, although I can't think of a better method at the moment.

EDIT: I think I misread the question - if all you're trying to do is find the zeros of the function, there are definitely better ways than using a Taylor series.

David Zaslavsky
No, you read it correctly - I'm not trying to find the roots, I'm trying to develop an algorithm that would work when programmed into a computer. I will try the method mentioned of just finding the taylor series for whole function.
Zachary
Actually, looking at it again, finding the series for the entire function doesn't look very trivial, considering f(0) doesn't exist. :\
Zachary
A: 

Turns out I was doing it correctly, and when checking the original function I forgot to take my calculator out of degree mode. :(

Zachary
+1  A: 

Method used in question is correct - just make sure your calculator is in radians mode.

Zachary