MATLAB calculating sine and cosine using Taylor series in Command Window

344 Views Asked by At

I'm trying to do an exercise that I really don't understand what or how to do it... or the part "Calculate sine and cosine according to formulas above with 7 expansion terms" do they mean that $n=7?$

Exe $\bf 1.5.2$ ($\bf 2$ points). Sine and cosine trigonometric functions can be presented as a series with the Taylor expansion \begin{align} \sin x &=\sum_{n=0}^{\infty} \frac{(-1)^n}{(2n+1)!} x^{2n+1}\\ \cos x &=\sum_{n=0}^{\infty} \frac{(-1)^n}{(2n)!} x^{2n}. \end{align} Calculate sine and cosine according to formulas above with $7$ expansion terms. The calculations should be performed in Command Window and should not exceed two lines.

1

There are 1 best solutions below

1
On

The basic point is that you can calculate approximate values of infinite sums by calculating the sum of the first $M$ values for some $M$, i.e:

$$\sin(x) = \sum_{n=0}^{\infty}\frac{(-1)^n}{(2n+1)!}x^{2n+1} \approx \sum_{n=0}^{M-1}\frac{(-1)^n}{(2n+1)!}x^{2n+1} $$

In your case you would take $M = 7$.

How good an approximation this is depends on the series and the value of $x$ - in general for this kind of power series the smaller $x$ is, the better an approximation it is. Increasing $M$ will also make a better approximation at the cost of increased computation time.