# Angle of 2 vectors

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?

-
$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
I did calculate it using inverse of the cosine and the answer to degrees however my answer is 52.125... What is really the answer to this? Thanks. –  mcxiand May 8 '12 at 4:24

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$.