Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have to change this formula: $$\frac{1-\cos(x)}{x}$$ so that I can avoid the cancellation error. I can do this for 0 but not for $π$. So I get: $$\frac{\sin^2(x)}{x(1+\cos(x))}$$ which for $x$ close to $0$ gets rid of the cancellation error. But I don't know how to fix the error for $x$ close to $π$? I just want to know if I should be using trigonometric identities again? I've tried to use trig identities but nothing works. Any suggestions or hints?

Edit: So for π I meant that sin(π) would be 0 so it wouldn't give me the correct value as (1-cosπ)/π=2/π. The second equation would overall give me 0. That's the error I meant for π. Sorry for the confusion there.

share|cite|improve this question
up vote 0 down vote accepted

Another possiblity that avoids cancellation error at both places is $$ \frac{2 \sin^2(x/2)}{x} $$

share|cite|improve this answer

The expression $\dfrac{1-\cos x}{x}$ becomes $0/0$ when $x=0$, but not when $x=\pi$. The expression $\dfrac{\sin^2 x}{x(1+\cos x)}$ becomes $0/0$ when $x=\pi$ but not when $x=0$. The two are equal to each other if $x$ is anything between $0$ and $\pi$. So you've got one form that "gets rid of the error" when $x=0$ and another form that "gets rid of the error" when $x=\pi$. The answer to your final question seems to be just to stick with what you started with.

share|cite|improve this answer

If I got you right:

$$ \lim_{x \to 0} \frac{1-\cos x}{x}= \lim_{x \to 0} \frac{1-(1-\frac{x^2}{2}+O(x^4))}{x}=0\\ \lim_{x \to \pi} \frac{1-\cos x}{x}=\frac{2}{\pi} $$ The first limit is due to Taylor series expansion around 0, the second is since $\cos \pi=-1$

share|cite|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.