GWU Making a 2D Vector Class Phyton Program File You should make sure that the code is running correct and include commentsRubric – Code runs, is fully tes

GWU Making a 2D Vector Class Phyton Program File You should make sure that the code is running correct and include commentsRubric – Code runs, is fully tested, and includes sufficient comments and supporting documentationI will attach you the assignment instruction below. Assignment 3
The Problem
We are going to experiment with making our own class. We are going to make a 2D vector
class.
Some Background
Here is a little background on two-dimensional vectors. A vector is basically an arrow that has a
magnitude (a length) and a direction (an angle with respect to typically the x axis). It usually is
represented as an x,y pair, where the origin of the vector is a 0,0 and the end of the vector is at
the listed pair.
x,y
V+W
V+W
W
V
0,0
A vector
V+W
V+V=2*V
W
V
V-W
-W
V*2
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 (note that this definition
uses addition and multiplication).
•
Vector Multiplication with another vector. There are two possibilities, dot product or
cross product. We’ll 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 !?? # + ?? # . You might look at math.hypot for this.
Your Tasks
Make a vector class. Provide the operators
__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

Purchase answer to see full
attachment

Don't use plagiarized sources. Get Your Custom Essay on
GWU Making a 2D Vector Class Phyton Program File You should make sure that the code is running correct and include commentsRubric – Code runs, is fully tes
For $10/Page 0nly
Order Essay
Calculator

Calculate the price of your paper

Total price:$26

Need a better grade?
We've got you covered.

Order your paper