In Exercises 31 – 32, approximate the value of the given def- inite integral by using the first 4 nonzero terms of the inte- grand’s Taylor series.
31.) \(\int^{\sqrt{\pi}}_{0} sin(x^2) dx\)
The Taylor Series for sin(x) is given by :
\(\sum_{n=0}^{\infty} (-1)^n \frac{x^{2n+1}}{(2n+1)!}\)
Now substitute in \(x^2\)
\(\sum_{n=0}^{\infty} (-1)^n \frac{(x^2)^{2n+1}}{(2n+1)!}\)
Calculate the first 4 terms:
\(sin(x^2) = x^2 - \frac{x^6}{6} + \frac{x^{10}}{120} - \frac{x^{14}}{5040} + ...\)
Now we can calculate the integral for each term over the interval \(0 \ to \ \sqrt \pi\) add them all up and get the approximation for the integral.
# Functions to integrate
first_term <- function(x){ x^2 }
second_term <- function(x){ x^6 / 6 }
third_term <- function(x){ x^10 / 120 }
fourth_term <- function(x){ x^14 / 5040 }
# Integrating each function
int1 <- integrate(first_term, 0, sqrt(pi))
int2 <- integrate(second_term, 0, sqrt(pi))
int3 <- integrate(third_term, 0, sqrt(pi))
int4 <- integrate(fourth_term, 0, sqrt(pi))
# Summing them up
approx_int <- int1$value - int2$value + int3$value - int4$value
# Display the approximate value of the integral
print(approx_int)
## [1] 0.8877069
fun <- function(x){sin(x^2)}
print(integrate(fun,0,sqrt(pi)))
## 0.8948315 with absolute error < 9.9e-15
Above you can see the Approximation from the Taylor series comes out to 0.8877069 and calling Rs’ built in integral function gives 0.8948315 with absolute error < 9.9e-15 so it seems to be a pretty good approximation.