In: Computer Science
Write a program in ecmascript, of Maclurin series of a sine function that declares two variables:
x is the value of the argument, h is the accuracy that you want test the program with
x= 1; h= .00001
print out the approximation using as many terms of the Maclaurin series that you need, but no more than that, to get within the required accuracy. While you are at it you might as well also print out Sine(x) BUT do not use the value of Sin(X) to determine the accuracy of the approximation.
Let f(x) = sin(x). To find the Maclaurin series coefficients, we must evaluate
for k = 0, 1, 2, 3, 4, ...
Calculating the first few coefficients, a pattern emerges:
The coefficients alternate between 0, 1, and -1. You should be able to, for the nth derivative, determine whether the nth coefficient is 0, 1, or -1.
Substitute Coefficients into Expansion
Thus, the Maclaurin series for sin(x) is
Step 3: Write the Expansion in Sigma Notation
From the first few terms that we have calculated, we can see a pattern that allows us to derive an expansion for the nth term in the series, which is
Substituting this into the formula for the Taylor series expansion, we obtain
Radius of Convergence
The ratio test gives us:
Because this limit is zero for all real values of x, the radius of convergence of the expansion is the set of all real numbers.
step 1
Maclaurin series coefficients, ak can be calculated using the formula (that comes from the definition of a Taylor series)
where f is the given function, and in this case is sin(x). In step 1, we are only using this formula to calculate the first few coefficients. We can calculate as many as we need, and in this case were able to stop calculating coefficients when we found a pattern to write a general formula for the expansion.
Step 2
Step 2 was a simple substitution of our coefficients into the expression of the Taylor series.
Step 3
A helpful step to find a compact expression for the nth term in the series, is to write out more explicitly the terms in the series that we have found:
We have discovered the sequence 1, 3, 5, ... in the exponents and in the denominator of each term. We may then find a way to convert this sequence that we have discovered, into the sequence k=0, 1, 2, ... that appears in the final summation. The simple transform 2k+1 performs this transformation for us.
Step 4
This step was nothing more than substitution of our formula into the formula for the ratio test. Because we found that the series converges for all x, we did not need to test the endpoints of our interval. If however we did find that the series only converged on an interval with a finite width, then we may need to take extra steps to determine the convergence at the boundary points of the interval.