Question: using python Create a class to handle x,y,z vectors. The class should have the following features 1) create a vector using v = myvector(x,y,z) to

using python

Create a class to handle x,y,z vectors. The class should have the following features

1) create a vector using v = myvector(x,y,z) to initialize the vector

2) find the magnitude of the vector v.mag() returns the magnitude

2) add two vectors so v1=myvector(x,y,z) v2=myvector(x,y,z) v3 = v1+v2

3) v.format() returns a string of the form xi + yj + zk

4) perform cross product when vectors are multiplied v3 = v1 * v2 v3 is the cross product v1 and v2

Program structure

complex class definition here...

# ------------- Main -----------

a = vector(1,2,1)

b = vector(4,1,7)

print(a.format(), "Mag = ", a.mag())

print(b.format(), "Mag = ", b.mag())

print("a + b =", (a.add(b)).format())

print("a cross b = ", (a.cross(b)).format())

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!