Advertisement
hiddenGem

Angle Between Vectors

Jul 7th, 2020
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 0.41 KB | None | 0 0
  1. %% Angle Between Vectors
  2. % Uses the dot product to calculate the angle between vectors
  3. a = input('Use brackets to enter the first vector\n');
  4. b = input('Use brackets to enter the second vector\n');
  5.  
  6. MagA = sqrt(sum(a.^2));
  7. MagB = sqrt(sum(b.^2));
  8.  
  9. thetad = acosd(dot(a,b)/(MagA*MagB));
  10. thetar = acos(dot(a,b)/(MagA*MagB));
  11. fprintf('The angle between the vectors is %.4f deg and %.4f rad', thetad, thetar);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement