{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

hw9 - Physics 503 Scientific Computing Homework#8 Topic...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
Physics 503: Scientific Computing Homework #8 Topic: Object Oriented Programming Due: Wed. Apr. 20 by the beginning of class please email your code as an attached file to [email protected] I would also like you to print out your programs (with comments) and any relevant plots to hand in at class time. Assignment Use object oriented programming techniques to create a 3D Vector object (class) . The object should initialize with a list of three components (x,y,z) which are optional (test if they are supplied, if not give default values of [1,0,0] ). It should be called like this: v1=Vector([2.4,3.1,0.5]) or v1=Vector() for default values. The Vector object should have the following methods: (assume v1 is a Vector object) 1. v1.setCoords([x,y,z]) 2. v1.x (as well as y and z) This would return the x component by v1.x, etc. 3. v1.mag() - return the magnitude of the vector 4. v1.dot(v2) - return the scalar product 5. v1.__add__(v2) which allows a user to add two vectors using the syntax ‘vsum=v1+v2’ Write a script which imports this class and puts it through a series of tests.
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

Ask a homework question - tutors are online