Computational Physics Lab I: Spring-2023 Challenge problem for Wednesday : Due Week 3
Taylor series approximation for cosine
S0 4245S
A Taylor series can be used to create an approximation for a function, which we
call a power series approximation. The Taylor series for cosine is:
\begin{align}
\cos(\theta) = \sum_{i=0}^{\text{even}} \frac{(-1)^{i/2}}{i!}\theta^{i}
\end{align}
where the sum goes to \(\infty\) over even values of \(i\).
Write a function that given \(\theta\) and \(i_{\max}\) computes the Taylor
series of \(\cos\theta\) including the terms up to and including
\(i=i_{\max}\).
Test your function by printing \(\cos(0.01)\) and a few approximations of this
with moderate \(i_{\max}\). Save these tests as part of your program.
Plot \(\cos\theta\) and be sure to label your axes.
Plot your Taylor series approximation for \(i_{\max}\) of 0, 1, 2, and 3. Use a legend to distinguish between your curves.