Chapter 3: Problem 21
Make a table for approximations of \(\cos x\). The function \(\cos (x)\) can be approximated by the sum $$ C(x ; n)=\sum_{j=0}^{n} c_{j} $$ where $$ c_{j}=-c_{j-1} \frac{x^{2}}{2 j(2 j-1)}, \quad j=1,2, \ldots, n $$ and \(c_{0}=1\). Make a Python function for computing \(C(x ; n)\). (Hint: Represent \(c_{j}\) by a variable term, make updates term = -term*... inside a for loop, and accumulate the term variable in a variable for the sum.) Also make a function for writing out a table of the errors in the approximation \(C(x ; n)\) of \(\cos (x)\) for some \(x\) and \(n\) values given as arguments to the function. Let the \(x\) values run downward in the rowsand the \(n\) values to the right in the columns. For example, a table for \(x=4 \pi, 6 \pi, 8 \pi, 10 \pi\) and \(n=5,25,50,100,200\) can look like \(\begin{array}{rccccc}\mathrm{x} & 5 & 25 & 50 & 100 & 200 \\ 12.5664 & 1.61 \mathrm{e}+04 & 1.87 \mathrm{e}-11 & 1.74 \mathrm{e}-12 & 1.74 \mathrm{e}-12 & 1.74 \mathrm{e}-12 \\ 18.8496 & 1.22 \mathrm{e}+06 & 2.28 \mathrm{e}-02 & 7.12 \mathrm{e}-11 & 7.12 \mathrm{e}-11 & 7.12 \mathrm{e}-11 \\ 25.1327 & 2.41 \mathrm{e}+07 & 6.58 \mathrm{e}+04 & -4.87 \mathrm{e}-07 & -4.87 \mathrm{e}-07 & -4.87 \mathrm{e}-07 \\ 31.4159 & 2.36 \mathrm{e}+08 & 6.52 \mathrm{e}+09 & 1.65 \mathrm{e}-04 & 1.65 \mathrm{e}-04 & 1.65 \mathrm{e}-04\end{array}\) Observe how the error increases with \(x\) and decreases with \(n .\) Name of program file: cossum.py.
Short Answer
Step by step solution
Key Concepts
These are the key concepts you need to understand to accurately answer the question.