Find a good strategy to compute$f(x) = e^x −\cos x − \sin x$ for $x$ near $0$ Find a good strategy to compute $f(x) = e^x − \cos x − \sin x$ for $x$ near 0.
In five-decimal-digit arithmetic, compute $f(0.1)$ using the straightforward method
and your better strategy, and compare the difference. (Hint: The computer can only
store numbers with five decimal digits at any step.)
so I know using the straightforward strategy that:
$f(0.1) = e^{(0.1)} - \cos(0.1) - \sin(0.1)$ (since the computer can only store 5 decimal digits at any step ->
$= 1.10517 - 0.99500 - 0.09998$
$= 0.01019 $
so I think my teacher mentioned something in class saying we should use either taylor or macclaurin series? Can someone walk me through how exactly I would do that for my "better" strategy?
 A: With Taylor series you have
$$\begin{align} f(x) &= \left(1 + x + \frac{x^2}{2} + \frac{x^3}{6} + \frac{x^4}{24} + \frac{x^5}{120} + \cdots \right)\\
&-\left(1 - \frac{x^2}{2} + \frac{x^4}{24} + \cdots\right)\\
&- \left(x - \frac{x^3}{6} + \frac{x^5}{120} + \cdots\right)\end{align}$$
Now, notice that the terms after $x^5$ were deliberately left out because they won't be significant if your computer can store only $5$ decimal places, as all these terms would be at least in the $6$th decimal place ($0.1^6, 0.1^7, \cdots$).
So you may as well leave those terms out and approximate $f$ as
$$$$\begin{align} f(x) &\approx \left(1 + x + \frac{x^2}{2} + \frac{x^3}{6} + \frac{x^4}{24} + \frac{x^5}{120} \right)\\
&-\left(1 - \frac{x^2}{2} + \frac{x^4}{24} \right)\\
&- \left(x - \frac{x^3}{6} + \frac{x^5}{120} \right)\end{align}$$$$
A: $e^x,\sin x,\cos x$ are entire functions, so for any $x\in\mathbb{R}$ the identity:
$$\begin{eqnarray*} f(x)=e^{x}-\sin(x)-\cos(x) &=& \sum_{n\geq 0}\frac{x^n}{n!}-\sum_{n\geq 0}\frac{(-1)^n}{(2n+1)!}x^{2n+1}-\sum_{n\geq 0}\frac{(-1)^n}{(2n)!}x^{2n}\\ &=& 2\cdot\sum_{n\in\{2,3\}\pmod{4}}\frac{x^n}{n!}\end{eqnarray*}$$
holds, so an extremely good approximation for your function in a neighbourhood of zero is given by the polynomial:
$$ p(x) = x^2+\frac{x^3}{3}+\frac{x^6}{360}+\frac{x^7}{2520} $$
whose value at $x=\frac{1}{10}$ is extremely close to $\color{red}{\large\frac{31}{3000}}$. 
Namely, the difference between $f\left(\frac{1}{10}\right)$ and $\frac{31}{3000}$ is less than $3\cdot 10^{-9}$.
