Computing Transcendental Functions
Total Page:16
File Type:pdf, Size:1020Kb
Computing Transcendental Functions Iris Oved [email protected] 29 April 1999 Exponential, logarithmic, and trigonometric functions are transcendental. They are peculiar in that their values cannot be computed in terms of finite compositions of arithmetic and/or algebraic operations. So how might one go about computing such functions? There are several approaches to this problem, three of which will be outlined below. We will begin with Taylor approxima- tions, then take a look at a method involving Minimax Polynomials, and we will conclude with a brief consideration of CORDIC approximations. While the discussion will specifically cover methods for calculating the sine function, the procedures can be generalized for the calculation of other transcendental functions as well. 1 Taylor Approximations One method for computing the sine function is to find a polynomial that allows us to approximate the sine locally. A polynomial is a good approximation to the sine function near some point, x = a, if the derivatives of the polynomial at the point are equal to the derivatives of the sine curve at that point. The more derivatives the polynomial has in common with the sine function at the point, the better the approximation. Thus the higher the degree of the polynomial, the better the approximation. A polynomial that is found by this method is called a Taylor Polynomial. Suppose we are looking for the Taylor Polynomial of degree 1 approximating the sine function near x = 0. We will call the polynomial p(x) and the sine function f(x). We want to find a linear function p(x) such that p(0) = f(0) and p0(0) = f 0(0). Since we are looking for a polynomial of degree 1, we know that it will be of the form p(x) = Bx + A: Now we set p(0) = f(0): Since we know that f(0) = 0, we have p(0) = 0: 1 Substituting x = 0 into p(x) gives p(0) = 0B + A: Thus, in our polynomial, we know the coefficient A = 0. To find the value of the coefficient B, we take the derivative of our linear function and we have: p0(x) = B: Now we set p0(0) = f 0(0): Since we know that the derivative of the sine function is the cosine function, we know that f 0(0) = cos(0) = 1. So we have p0(0) = 1: Substituting x = 0 into p0(x), we get p0(0) = B: Thus we have the coefficient B = 1. Now that we have both coefficients, we arrive at the Taylor Polynomial of degree 1 that approximates the sine curve near x = 0: p(x) = x: Notice that this is the line tangent to the sine function at x = 0.1 1Indeed, the degree 1 Taylor Polynomial of any function is necessarily the line tangent to the function at the point about which the above procedures are performed. 2 4 3 2 -6 -4 -2 2 4 6 -2 -4 Figure 1.1. Sine curve and degree 1 Taylor with −2π ≤ x ≤ 2π We can see in Figure 1.1 that the degree 1 Taylor Polynomial is a good approximation to the sine curve near x = 0, but clearly it gets worse as we move farther away from that point. Higher degree polynomials have a higher number of meaningful derivatives (derivatives not equal to zero). Higher degree Taylor Polynomials thus have more derivatives in common with the function that is being approximated. This means that the higher the degree of the Taylor Polynomial, the more accurately it approximates the sine function. To demonstrate this, let us find the Taylor Polynomial of degree 3, for the sine curve, centered at x = 0. Since we are looking for a polynomial of degree 3, we know that it will be of the form p(x) = Dx3 + Cx2 + Bx + A: As before, we set p(0) = f(0); and conclude that in our polynomial we have the coefficient A = 0. Next, to find the coefficient B, we take the first derivative of our polynomial and get p0(x) = 3Dx2 + 2Cx + B: Now we set p0(0) = f 0(0); and we have the coefficient B = 1. Now, to find the coefficient C, we take the second derivative of our polyno- mial and get p00(x) = 6Dx + 2C: Next we set p00(0) = f 00(0): Since we know that the derivative of the cosine function is the negative of the sine function, we know that f 00(0) = − sin(0) = 0. So we have p00(0) = 0: Substituting x = 0 into p00(x), we get p00(0) = 2C: Thus we have the coefficient C = 0. Finally, to find the coefficient D, we take the third derivative of our polyno- mial and get p000(x) = 6D: Now we set p000(0) = f 000(0): 4 Since we know that the derivative of the negative of the sine function is the negative of the cosine function, we know that f 000(0) = − cos(0) = −1. So we have p000(0) = −1: Substituting x = 0 into p000(x), we get p000(0) = 6D: Thus we have the coefficient D = −1=6. By this method, we have discovered that the degree 3 Taylor Polynomial that approximates the sine function near x = 0 is 1 3 2 p(x) = − 6 x + 0x + x + 0: 5 4 6 2 -6 -4 -2 2 4 6 -2 -4 Figure 1.2. Sine curve and degree 3 Taylor with −2π ≤ x ≤ 2π Although the degree 3 Taylor Polynomial is a better approximation than the degree 1 Taylor Polynomial, it still becomes very inaccurate as we move farther away from x = 0. The general formula for the Taylor Polynomial of degree n approximating some function f(x) for x near 0 is f 00(0) f 000(0) f (n)(0) f(0) + f 0(0)x + x2 + x3 + ··· + xn: 2! 3! n! So suppose we want to find the Taylor polynomial of degree 9 that approxi- mates the sine function near x = 0.2 Substituting f(x) = sin(x) and n = 9 into the general formula gives x3 x5 x7 x9 x − + − + : 3! 5! 7! 9! 2Since sin(−x) = − sin(x), there are no interesting even-degree Taylor Polynomials at x = 0. 7 4 8 2 -6 -4 -2 2 4 6 -2 -4 Figure 1.3. Sine curve and degree 9 Taylor Polynomial with −2π ≤ x ≤ 2π Figure 1.3 shows that the Taylor Polynomial of degree 9 is a better approxi- mation to the sine curve than the linear and cubic polynomials. Still, even this high degree polynomial provides approximations that become worse as we move farther away from x = 0. We can arrive at better and better approximations to the sine curve if we find Taylor Polynomials of higher and higher degree. However, no matter how large the degree of the polynomial, since the sine curve is periodic, while polynomials are not, there will always be a point at which the graph of the polynomial will deviate significantly from the sine curve in some direction. This is to be expected because the sine function is transcendental. No finite composition of arithmetic and/or algebraic operations will capture the behavior of a transcendental function. One solution to this problem is to limit the sine curve to a domain of x- values from which we can infer the sine of any real number. Since the sine function has a period of 2π, it is clear that we can infer the sine of any real number if we can calculate the sine of any real x in the domain 0 ≤ x ≤ 2π. In this domain, the sine function has a finite number of turns, so a high degree polynomial would be an adequate approximation to the curve for all real x in the domain. However, we would benefit by further reducing the domain of inputs so that each of the inputs will be even closer to x = 0. This is important because Taylor Polynomials are good approximations near a point, but not so good farther away from that point. 9 1 10 0.5 1 2 3 4 5 6 -0.5 -1 Figure 1.4. Sine curve with 0 ≤ x ≤ 2π If we look at the sine curve in the domain 0 ≤ x ≤ 2π, we can see that the domain can be further limited. Notice that all of the sine-values at inputs between π and 2π are negations of values between 0 and π. As long as we make a note to negate our solution, we can infer the sine of all of the x-values in the domain π ≤ x ≤ 2π, from the sine of the x-values in the domain 0 ≤ x ≤ π. A polynomial of high degree that resembles the sine curve in this domain will provide information from which we can infer a reasonable appproximation to the sine of any real x. Still, there is some symmetry in the sine curve that we can π exploit to shrink the domain further. The sine of the x-values between 2 and π π can be inferred from the sine of the x-values between 0 and 2 by reflecting π across the line x = 2 . Now the Taylor Polynomial only needs to be a good π approximation to the sine curve over the limited domain 0 ≤ x ≤ 2 in order for us to compute the sine function for any real input. 11 1 12 0.8 0.6 0.4 0.2 0.25 0.5 0.75 1 1.25 1.5 π Figure 1.5.