O Sweet Mr Math

wherein is detailed Matt's experiences as he tries to figure out what to do with his life. Right now, that means lots of thinking about math.

Friday, September 10, 2010

8:52 PM

The Taylor series approximation of ex converges rapidly for small positive values of x, but gives incorrect results for negative values, because computing the series requires subtracting large numbers from each other to get a small number, and on a computer this will introduce rounding errors.

The solution is to rewrite ex as 1/e−x when x<0. This can be computed without rounding errors reducing the accuracy of the final result. This solution is straightforward, but it was not obviously necessary in the original computation. The lesson, again, is to watch out for rounding errors.

The Taylor series approximation of ex is accurate for larger positive values of x, but the number of terms that must be computed in order for the approximation to converge increases as x increases. This is a problem, because each term of the Taylor series has xn in the numerator. If the number of required terms gets too large, xn will become too large for the computer to represent and the computation will fail. My calculator gives e79 as 2.038281066651×1034. The Taylor series approximation returns infinity, because it requires more than 163 terms and 79163 is greater than the computer can represent.

Once again, the solution is to rewrite the original function. x can be broken up into an integer part and a fractional part, and then ex=einteger part×efractional part. efractional part can be calculated as a Taylor series expansion. If e is stored as a constant, then einteger part can be directly multiplied out, and this can be computed when a strict Taylor series approximation of ex fails.

Taylor series can also be used to approximate sin(x) and cos(x). Like with ex, the series require fewer terms to converge near 0, so the identities sin(x)=sin(x+2πn) and cos(x)=cos(x+2πn) for all positive and negative integer values of n should be used so the Taylor series is only computed for −π<x<π.

Finally, Taylor series can be used to approximate ln(x). The catch here is that ex, sin(x), and cos(x) are all computed based the difference between x and 0, while ln(x) must be computed based on the difference between x and 1. This makes the math a little messier but isn't otherwise a big deal. However, the Taylor series for ln(x) does not converge for x>2. Since ln(x) = −ln(1/x), to compute ln(x) for x≥2, compute −ln(1/x) instead.

0 comments

RSS

FAQ

What does "rolls a hoover" mean, anyway?

"Roll a hoover" was coined by Christopher Locke, aka RageBoy (not worksafe). He enumerated some Hooverian Principles, but that might not be too helpful. My interpretation is that rolling a hoover means doing something that you know is stupid without any clear sense of what the outcome will be, just to see what will happen. In my case, I quit my job in an uncertain economy to try to start a business. I'm still not sure how that will work out.

Why is the HTML for this page not valid?

BlogSpot adds the advertisement that appears at the top of this page. That advertisement is not valid HTML and is outside of my control. I believe that aside from that ad, this page is valid HTML.