Write Python commands, within a print command, that output the following. (E.g. print(list(range(10))) , in spyder (vi) Let x = [1,3,5] and let y = [2,4,6]. If we interpret these as vectors x and y then the vector sum can be written x + y = [x[0]+y[0],x[1]+y[1],x[2]+y[2]]. Find an the equivalent expression for the vector dot product x⋅y. (vii) With x,y as above find an expression for the vector cross product x * y.
Write Python commands, within a print command, that output the following. (E.g. print(list(range(10))) , in spyder
(vi) Let x = [1,3,5] and let y = [2,4,6]. If we interpret these as
(vii) With x,y as above find an expression for the vector cross product x * y.
- Code:
x = [1, 3, 5]
y = [2, 4, 6]
dot_product = sum(x[i] * y[i] for i in range(len(x)))
print("The vector dot product x⋅y is:", dot_product)
- Output:
The vector dot product x⋅y is: 44
- Explanation:
This code calculates the dot product by multiplying the corresponding components of the vectors x and y and then summing up the results.
Step by step
Solved in 3 steps with 2 images