Question: PYTHON CLASS QUESTION(Vector examples below) Here are some of the operations you can perform on a vector. vector addition. If V1 is (x,y) and V2

PYTHON CLASS QUESTION(Vector examples below)

Here are some of the operations you can perform on a vector.

vector addition. If V1 is (x,y) and V2 is (a,b), the V+W is (x+a,y+b), a vector

vector multiplication by a scalar. if V1 is (x,y), the V*n is (x*n,y*n), a vector

vector subtraction V-W is the same as V+(W*-1), a vector

vector multiplication with another vector. There are two possibilities, dot product or cross product. Well do dot product. If V=(x,y) and W=(a,b), then V*W = x*a + y*b, a scalar. Thus the dot product yields a scalar, not a vector

vector magnitude. The magnitude based on the Pythagorean theorem for a V=(x,y) says that the magnitude is sqrt(x^2 + y^2) might look at math.hypot for this

!, Question: Your Tasks is to Make a vector class. Provide the operators with documentation.

__init__ # constructor, takes 3 args: self,x,y . No return

__str__ # for printing, takes 1 arg self. Returns a string

__add__ # vector + vector. Takes 2 args, self and vector. Returns a new vector

__sub__ # vector vector. Takes 2 args, self and vector. Returns a new vector

__mul__ # two possibilities. vector*integer or vector*vector (dot product). Get it to do just one of

# the two at first, then see if you can use introspection to do both

magnitude # magnitude of the vector. One arg, self. Returns a float

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!