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?

  • 2
    $v$ should be the inverse cosine of that number, not the cosine.2012-05-08
  • 4
    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.2012-05-08
  • 0
    @Alex: That comment is of answer quality!2012-05-08
  • 0
    My mistake it should be a = 5,1 b = 2,4. I'll edit.2012-05-08
  • 0
    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.2012-05-08
  • 1
    It appears you have the right answer. So, why do you say, "supposedly the answer is 35.18 degrees"?2012-05-08
  • 0
    @GerryMyerson I was doing a programming task and given the formula. And a run through like on the image above. But the final answer on the specs stated that its 35.18 degrees. That is why im confused. And i could not verify it.2012-05-08
  • 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$.