Chapter 5: Problem 20
Plot Taylor polynomial approximations to \(\sin x\). The sine function can be approximated by a polynomial according to the following formula: $$ \sin x \approx S(x ; n)=\sum_{j=0}^{n}(-1)^{j} \frac{x^{2 j+1}}{(2 j+1) !} $$ The expression \((2 j+1) !\) is the factorial (see Exercise 3.14). The error in the approximation \(S(x ; n)\) decreases as \(n\) increases and in the limit we have that \(\lim _{n \rightarrow \infty} S(x ; n)=\sin x\). The purpose of this exercise is to visualize the quality of various approximations \(S(x ; n)\) as \(n\) increases. The first part of the exercise is to write a Python function \(\mathrm{S}(\mathrm{x}\), (n) that computes \(S(x ; n)\). Use a straightforward approach where you compute each term as it stands in the formula, i.e., \((-1)^{j} x^{2 j+1}\) divided by the factorial \((2 j+1) !\). (We remark that Exercise A.16 outlines a much more efficient computation of the terms in the series.) The next part of the exercise is to plot \(\sin x\) on \([0,4 \pi]\) together with the approximations \(S(x ; 1), S(x ; 2), S(x ; 3), S(x ; 6)\), and \(S(x ; 12)\) Name of program file: plot_Taylor_sin.py.
Short Answer
Step by step solution
Key Concepts
These are the key concepts you need to understand to accurately answer the question.