Advertisement
Mrinmoyst_1

Untitled

Aug 24th, 2024
251
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 0.32 KB | None | 0 0
  1. % Given vectors
  2. A = [5, 3, 1];
  3. B = [-1, 2, 0];
  4.  
  5. % Magnitudes
  6. mag_A = norm(A);
  7. mag_B = norm(B);
  8.  
  9. % Dot products of A and B
  10. dot_AB = dot(A, B);
  11.  
  12.  
  13. %Cosine
  14. cos_theta = dot_AB/(mag_A*mag_B);
  15.  
  16. %Angle in degree
  17. theta = acosd(cos_theta);
  18.  
  19. %Result
  20. fprintf('The angle between vectors A and B is %.2f degrees\n', theta);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement