I'm trying to approximate the trigonometric functions for a code library, and I want to ask if this is a good way to go about it. I'm aware of the Taylor series approach, but I wanted to go with something different this time around.
Euler's formula is a vague term, since "Euler" is the German word for "a suprising connection," which describes many mathematical concepts. I'm refferring to the formula $e^{ix}=\cos(x)+i\sin(x)$, though $x$ is commonly written as $\theta$, since that's useful for many applications.
My idea is that, since $e^A=\sum_{k=0}^{\infty}\frac{1}{k!}A^k$ (the formula often used to plug non-real inputs into the exponential formula), it should be possible to simplify the expression when $A=ix$. What I found was that, since $(ix)^k=i^k \cdot x^k$, and $i^k$ is cyclic, I could split the sum into $$\sum_{k=0}^{\infty}\frac{1}{k!}x^{4k}+i\sum_{k=0}^{\infty}\frac{1}{k!}x^{4k+1}-\sum_{k=0}^{\infty}\frac{1}{k!}x^{4k+2}-i\sum_{k=0}^{\infty}\frac{1}{k!}x^{4k+3}$$ Which is very convenient, since $ \Re(e^{ix})=\cos(x)$ & $\Im(e^{ix})=\sin(x)$. If I apply these operations to the above formula, I find that $$\sin(x)=\sum_{k=0}^{\infty}\frac{1}{k!}(x^{4k+1}-x^{4k+3})$$ $$\cos(x)=\sum_{k=0}^{\infty}\frac{1}{k!}(x^{4k}-x^{4k+2})$$ And this works for $\tan(x)$ since $\tan(x)=\frac{\sin(x)}{\cos(x)}$. To turn this into an approximation, we can use the defenition of infinite sums to replace infinity with $\lim_{h\to \infty}$ and use higher and higher values of $h$ to approximate $\sin(x)$ and $\cos(x)$. However, despite this, whenever I evaluate for any value of $h$, even very high values, it doesn't seem to stay near to the function it's approximating for even a few $\pi$s worth.
Have I done something wrong? Or is this just a fundamentally flawed idea?
\begin{align*}e^{ix}&=\sum_{k=0}^{\infty}\frac{x^k}{k!}i^k=1+\frac {ix}{1}+\frac {(ix)^2}{2!}+\frac {(ix)^3}{3!}+\ldots=1+\frac {ix}{1}-\frac {x^2}{2!}-\frac {x^3}{3!}i+\frac {x^4}{4!}+\ldots \\ &=\left({1-\frac {x^2}{2!}+\frac {x^4}{4!}+\ldots}\right)+i\left({x-\frac {x^3}{3!}+\cdot\cdot\cdot}\right) =\cos(x)+i\sin(x)\end{align*}