Approximate the value of the given definite integral by using the first 4 non-zero terms of the integrand’s Taylor series.
\[\int_{0}^{\pi^2/4 } \cos( \sqrt{x}) dx \]
First, we obtain the exact answer explicitly and then compare that analytical solution to the Taylor series approximation.
Let \(w = \sqrt{x}\) then \[ dw = 1/2x^{-1/2}dx \implies dw = 1/2 w^{-1} dx \implies 2w dw = dx \]
This means
\[\int_{0}^{\pi^2/4} \cos(\sqrt{x}) dx = \int_{w=0}^{w=\pi/2} \cos(w) 2w dw \]
We can solve the right hand side using integration by parts
\[ \begin{align} \int_{w=0}^{w=\pi/2} \cos(w) 2w dw & = 2w\sin(w) \bigg\rvert_{0}^{\pi/2}- \int_{w=0}^{w=\pi/2} \sin(w) 2dw \\ & = (2w \sin(w) + 2 \cos(w)) \bigg\rvert_{0}^{\pi/2} \\ & = \left[ 2(\pi/2)\sin(\pi/2) + 2 \cos(\pi/2) \right] - \left[ 2 (0) \sin(0) + 2 \cos(0) \right] \\ & = [ \pi + 0] - [ 2\cdot 1] \\ & = \pi - 2 \\ \int_{0}^{\pi^2/4} \cos(\sqrt{x})dx & \approx 1.1415926... \\ \end{align} \]
We know that the Taylor series of \(\cos(u)\) is:
\[ \begin{align} \cos(u) & = 1 - \frac{u^2}{2!} + \frac{u^4}{4!} - \frac{x^6}{6!} \\ \end{align} \] Plugging in \(u = \sqrt{x}\) gives the expansion:
\[\begin{align} \cos(\sqrt{x}) & = 1 - \frac{(\sqrt{x})^2}{2!} + \frac{ (\sqrt{x})^4 }{4!} - \frac{(\sqrt{x})^6}{6!} + \ldots \\ & = 1 - \frac{x}{2!} + \frac{x^2}{4!} - \frac{x^3}{6!} + \ldots \\ \int \cos( \sqrt{x} dx) & = x - \frac{x^2}{2 \cdot 2!} + \frac{x^3}{3 \cdot 4!} - \frac{x^4}{4 \cdot 6!} + \ldots \end{align} \] This implies the definite integral can be approximated by summing the first four terms of the RHS:
\[ \int_{0}^{\pi^2/4} \cos(\sqrt{x}) dx \approx \frac{\pi^2}{4} - \frac{\pi^4}{16 \cdot 2 \cdot 2!} + \frac{\pi^6}{64 \cdot 3 \cdot 4!} - \frac{\pi^8}{4^4 \cdot 4 \cdot 6!} \] We use R to calculate the numerical value.
Taylor <- function(x){
x - (x^2)/(2 * factorial(2)) + (x^3)/(3* factorial(4) ) - (x^4)/(4 * factorial(6))
}
(definite_integral = Taylor( (pi^2)/4) )
## [1] 1.141149
This solution is correct to the 3rd decimal place and proves the result.