# 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. 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 !?? # + ?? # . 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

## We've got everything to become your favourite writing service

### Money back guarantee

Your money is safe. Even if we fail to satisfy your expectations, you can always request a refund and get your money back.

### Confidentiality

We don’t share your private information with anyone. What happens on our website stays on our website.

### Our service is legit

We provide you with a sample paper on the topic you need, and this kind of academic assistance is perfectly legitimate.

### Get a plagiarism-free paper

We check every paper with our plagiarism-detection software, so you get a unique paper written for your particular purposes.

### We can help with urgent tasks

Need a paper tomorrow? We can write it even while you’re sleeping. Place an order now and get your paper in 8 hours.

### Pay a fair price

Our prices depend on urgency. If you want a cheap essay, place your order in advance. Our prices start from $11 per page.