Tuesday, November 28, 2023

Products

 Vectors, it will be recalled, have both length and direction. One can multiply one with the other

to find magnitude with the dot product. 



The result is a scalar. We are still in a 2D space and need the cos value to correct the

outcome as a function of orientation.





The cross product is something else: we are still multiplying the absolute length values,

but correcting with the sine function, and + or - orientation. The result here is a new

vector, but in a 3D space.

                                                                       


                                                                  








                                                                                 




import numpy as np

# Define the two vectors
vector1 = np.array([2, 3])
vector2 = np.array([-4, 5])

# Calculate the cross product
cross_product = np.cross(vector1, vector2)

# Print the result
print(cross_product)

import matplotlib.pyplot as plt
import numpy as np

# Define the vector
#vector = np.array([1, 2, 3])
vector = ([2, 3, 0])
vector1 = ([-4, 5, 0])
vector2 = ([0, 0, cross_product])


# Create a figure and axis object
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')

# Draw the vector using quiver()
ax.quiver(0, 0, 0, vector[0], vector[1], vector[2], color='orange')
ax.quiver(0, 0, 0, vector1[0], vector1[1], vector1[2], color='red')
ax.quiver(0, 0, 0, vector2[0], vector2[1], vector2[2], color='black')

# Set the x, y, and z limits of the plot
ax.set_xlim([-5, 5])
ax.set_ylim([-5, 5])
ax.set_zlim([-5, 5])

# Add a grid to the plot
ax.grid(True)

# Show the plot
plt.show()

                                                                                  

*     *     *


                                                                                                


                                                                       

No comments: