33.7k views
1 vote
write python code that computes the angle between two vectors v=[10,9,3] and w=[2,5,12].use the Numpy function cross to compute the cross product of v and w. Then get dot product of the resulting cross product vector with v and w. What is the result? What is your take on the result?

1 Answer

4 votes

Final answer:

The code calculates the angle between two vectors using the cross and dot product in Python with NumPy. The cross product gives a vector orthogonal to the originals, and its dot product with either original vector should be zero, confirming orthogonality.

Step-by-step explanation:

The question involves calculating the angle between two vectors using the cross product and dot product in Python with the help of the NumPy library. The vectors in question are v=[10,9,3] and w=[2,5,12]. To compute the angle, we first calculate the cross-product to get a vector perpendicular to both v and w. Following that, we find the dot products of this new vector with the original vectors v and w. The expected result of these dot products would be zero because the cross-product vector is orthogonal to both v and w.

Here is the Python code to perform these computations:

import numpy as np

v = np.array([10, 9, 3])
w = np.array([2, 5, 12])

# Compute the cross product
cross_product = np.cross(v, w)

# Compute the dot products with v and w
dot_v = np.dot(cross_product, v)
dot_w = np.dot(cross_product, w)

# Print the results
print('Dot Product with v:', dot_v)
print('Dot Product with w:', dot_w)

The result for both dot_v and dot_w should indeed be zero, demonstrating the orthogonality of the cross-product to the original vectors. If non-zero results are obtained, this could indicate a mistake in calculations or a misunderstanding of the vector properties.

User Stefan Feuerhahn
by
8.0k points