title: Why do I get a complex number using acos?
body: <p>For example, if I use the following code to calculate the angle between two vectors <code>x</code> and <code>p</code>:</p>
  
  <pre><code>x = [1 1 -1];
  p = [-1 -1 1];
  
  angle = acos(dot(x,p) / (norm(x) * norm(p)));
  </code></pre>
  
  <p>it shows that <code>angle = 3.141592653589793 - 0.000000021073424i</code>, which is a complex number.</p>
  
  <p>But we all know that the dot product of <code>x</code> and <code>p</code> is -3, and the product of the norms of <code>x</code> and <code>p</code> is 3, so <code>angle = acos(-3/3)</code>, so angle should be exactly pi, 3.14159. Why does MatLab give a complex number, and how do I make the result a real number instead?</p>