1
$\begingroup$

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?

  • 0
    Thank you very much for helping.2012-05-08

1 Answers 1

3

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