I am asked to approximate $\displaystyle\int_{-1/2}^{1/2}\cosh(x^2)dx$ with an error less than $\frac{1}{1000}$. I know so far that $\displaystyle\cosh(x) = \displaystyle\sum_{i=0}^{\infty} \dfrac{i^{2n}}{2n!}x^{2n}$ and I can approximate values of $\cosh(x)$ with an error as small as I want to. I know that to approximate the integral I must integrate the series I found but I don't really know at what point I should stop it.
Approximating an integral with taylor polynomials.
power seriessequences-and-seriestaylor expansion
Related Solutions
Do as you mention and center the Taylor series at $0$. Look at it once with $x=1/5$, and again with $x=1/239$, and combine the two results. When you look at it with $x=1/5$, you may need to look at a higher degree Taylor polynomial to get six decimal places of accuracy than you do when you look at it with $x=1/239$. In that sense, you will be looking at Taylor polyonomials plural.
It could be easier to use the fundamental theorem of calculus $$F(x) = \int_{0}^{x} (1+t^2)\cos(t^2)\,dt \implies F'(x)=(1+x^2)\cos(x^2)$$ Now, let $y=x^2$ and you should arrive at $$F'(x)=1+\sum_{n=1}^\infty\frac{n \sin \left(\frac{\pi n}{2}\right)+\cos \left(\frac{\pi n}{2}\right)}{n!} x^{2n}$$ and integrating termwise $$F(x)=x+\sum_{n=1}^\infty\frac{n \sin \left(\frac{\pi n}{2}\right)+\cos \left(\frac{\pi n}{2}\right)}{(2n+1)n!} x^{2n+1}$$ This is an alernating series. So, if you write $$F(x)=x+\sum_{n=1}^{p-1}\frac{n \sin \left(\frac{\pi n}{2}\right)+\cos \left(\frac{\pi n}{2}\right)}{(2n+1)n!} x^{2n+1}+\sum_{n=p}^\infty\frac{n \sin \left(\frac{\pi n}{2}\right)+\cos \left(\frac{\pi n}{2}\right)}{(2n+1)n!} x^{2n+1}$$ The first neglected term is $$R_p=\frac{p \sin \left(\frac{\pi p}{2}\right)+\cos \left(\frac{\pi p}{2}\right)}{(2p+1)p!} x^{2p+1} $$ which makes $$R_{2p}=\frac{x^{4 p+1}}{(4 p+1) (2 p)!}\sim \frac{x^{4 p+1}}{2 (2 p+1)!} \qquad\text{and}\qquad R_{2p+1}=\frac{x^{4 p+3}}{(4 p+3) (2p)!}\sim \frac{x^{4 p+3}}{2 (2 p+1)!}$$
So, depending on the value of $x$ we need to solve either $$(2p+1)!=\frac 1{2x} (x^2)^{(2p+1)} 10^k\qquad\text{or}\qquad (2p+1)!=\frac x{2} (x^2)^{(2p+1)} 10^k $$ in order to have $R \leq 10^{-k}$.
Have a look at this question of mine; you will find a magnificent approximation provided by @robjohn, an eminent user on this site. Adapted to your problem, this would give $$2p+1 \sim e x^2 \exp\Big[{W\left(2 \log \left(\frac{10^k}{8 \pi x^3}\right)\right) }\Big]-\frac 12$$ $$2p+1 \sim e x^2 \exp\Big[{W\left(2 \log \left(\frac{10^k}{8 \pi x}\right)\right) }\Big]-\frac 12$$ where $W(.)$ is Lambert function.
Applied to $x=1$ and $k=3$, both formulae will give $p=5.68784$, that is to say $p=6$.
Best Answer
Here is a way to bound $M$. First note that$$\cosh x^2=\sum_{n=0}^{\infty}{x^{4n}\over 2n!}$$therefore$$I=\int_{-1\over 2}^{1\over 2}\cosh x^2dx=2\int_{0}^{1\over 2}\cosh x^2dx=2\int_{0}^{1\over 2}\sum_{n=0}^{\infty}{x^{4n}\over 2n!}dx=2\sum_{n=0}^{\infty}{\left({1\over 2}\right)^{4n+1}\over 2n!(4n+1)}$$if we approximate the integral up to $M$ terms we have:$$\hat I=2\sum_{n=0}^{M}{\left({1\over 2}\right)^{4n+1}\over 2n!(4n+1)}$$therefore the approximation error would become:$$|I-\hat I|=2\sum_{n=M+1}^{\infty}{\left({1\over 2}\right)^{4n+1}\over 2n!(4n+1)}<\sum_{n=M+1}^{\infty}\left({1\over 2}\right)^{4n}={1\over 15}\left({1\over 16}\right)^{M}$$if we wish to have the error below $0.001$ we should have:$${1\over 15}\left({1\over 16}\right)^{M}<0.001$$or equivalently $$M=2$$