1

So I'm kind of stuck on this question and I don't exactly know how to describe this on the title header and I apologize...

For some values of $x$, the assignment statement $y := 1-\cos(x)$ involves a difficulty. What is the difficulty? What values of $x$ are involved? What remedy do you propose to resolve this difficulty?

I know that this question does seem bleak and looks confusing, but any help I get would be appreciated! Thank you!

2 Answers2

6

The point is that when $x$ is small, $\cos(x) \approx 1$ and so you can expect loss of precision in $y$.

One remedy is this:

$$1-\cos(x) = (1-\cos(x)) \dfrac{1+\cos(x)}{1+\cos(x)} = \dfrac{1-\cos^2(x)}{1+\cos(x)}=\dfrac{\sin^2(x)}{1+\cos(x)}$$
For $x$ really small, you may was well take $\cos(x) \approx 1 - \frac{x^2}{2}$, which gives $1-\cos(x) \approx \frac{x^2}{2}$; this is consistent with the expression above, since $\sin(x)\approx x$ and $\cos(x)\approx 1$, but is much simpler.

lhf
  • 216,483
  • I'm kind of confused as to how you did the second part. How did you get the '1-x^(2)/2' notation? Plus how do you know 'sin(x) ≈ x' and 'cos(x) ≈ 1'? – user3390252 Oct 23 '14 at 06:49
  • 1
    @user3390252, from their Taylor series. – lhf Oct 23 '14 at 10:13
  • I don't understand the sin(x) = x and cos(x) = 1 part. – user3390252 Oct 23 '14 at 16:56
  • @user3390252, for very small angles the numerical value of $\sin(\theta)$ and $\theta$ are very close to being the same. Similarly for $\cos(\theta)$ and $1-\theta^2/2$ (just try it on your calculator for angles of about a degree or less). These are called small angle identities and can be understood to come from the Taylor series of the sine and cosine functions. These identities can be very useful in cases such as your own because we can then see that $1-\cos(x) \approx 1-(1-x^2/2) = x^2/2$ if $x$ is close to $0$. – Spencer Oct 24 '14 at 21:56
2

Another remedy,

$$1-\cos(x) = 2\sin^2(x/2)$$

Spencer
  • 12,271