Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. It's 100% free, no registration required.

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

Suppose I have 2 vectors $\vec{a}= (5,1)$ and $\vec{b}= (2,4)$. I want to compute the angle between them.

See my calculations below. Supposedly the answer is $35.18^{\circ}$ degree but my answer as seen below is not.

I use my calculations using C# .Net

 double scalarProduct = a1 * b1 + a2 * b2;
 double sqrA = Math.Pow(a1,2) + Math.Pow(a2,2);
 double sqrb = Math.Pow(b1, 2) + Math.Pow(b2, 2);
 double v = Math.Cos(scalarProduct/(Math.Sqrt(sqrA*sqrb)));

What went wrong?

share|cite|improve this question
$v$ should be the inverse cosine of that number, not the cosine. – Gerry Myerson May 8 '12 at 3:47
There are numerous issues here. First, you state originally that $$a=\binom 5 2 \text{ and } b=\binom 1 4$$ but that is not what you have in your image. Also, in the last line you should have taken the inverse of the cosine rather than the cosine. This returns the answer in radians in most implementations, which you would then need to convert to degrees. – Alex Becker May 8 '12 at 3:48
@Alex: That comment is of answer quality! – The Chaz 2.0 May 8 '12 at 4:16
My mistake it should be a = 5,1 b = 2,4. I'll edit. – mcxiand May 8 '12 at 4:18
It appears you have the right answer. So, why do you say, "supposedly the answer is 35.18 degrees"? – Gerry Myerson May 8 '12 at 4:26
up vote 3 down vote accepted

In the last line, you should take the inverse cosine of both sides rather than the cosine, which gives $$v=\cos^{-1}(\cos(v))=\cos^{-1}\left(\frac{14}{\sqrt{26}\cdot \sqrt{20}}\right)=.90975$$ which can be converted to degrees by multiplying by $\frac{180^\circ}{\pi}$, giving $52.13^\circ$.

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.