In: Computer Science
I am not even sure what the question is for the problem below, but I have highlighted what I think the question is further down:
Let v = (v1, v2) and w = (w1, w2) be vectors in 2 space.
The Scalar Product of v and whose notation is v (dot) w, is defined as follows: V (dot) w : = v1*w1 + v2 *w2
The scalar product (aka inner product, or dot product) Scalar product of 2 vectors in 2-space using 4 float parameters (the function scalarProduct 1)
ACTUAL QUESTION (I think ) - Code the following in Python:
Write a docstring; then write some test function calls; then implement the body of the function
Some test data: (1., 1.) · (2,3) = 5 (or, as a function call: scalarProduct1)
(1., 1., 2., 3.) (1.,1.) · (2,0) = 2
(1., 1.) · (0,2) =2
(1., 1.,) · (4,5) =23
#ScalarProduct function
#It takes two vectors as input arguments
#It returns sum as output
def scalarProduct1(vect1, vect2):
return sum(i*j for i,j in zip(vect1,vect2))
#defining vectors 1 and 2
vector1 = [2,3]
vector2 = [1,2]
print("Scalar Product of given vectors is : ")
#Calling function defined above to calculate the dot product.
print(scalarProduct1(vector1,vector2))
Attaching Screenshot
Feel free to ask any doubts, if you face any difficulty in understanding.
Please upvote the answer if you find it helpful