Question: In this assignment, your main task is to write a function in python that calculates the gravitational force vector between two objects. We will split

In this assignment, your main task is to write a function in python that calculates the gravitational force vector between two objects. We will split up this task into multiple smaller functions, and test each
one as we go. You must write docstrings for your functions and use comments to describe what is happening in your code.
As youre writing, it will be helpful to have some real numbers to test each function individually.
Lets say the Earth is particle 0 with m0=6.0\times 1024 kg, and the Sun is particle 1 with
m1=2.0\times 1030 kg. Lets put these at initial (x, y, z) positions of ~r0=(1.37,1.50,1.30) AU for
the Earth and ~r1=(0.50,2.00,1.30) AU for the Sun.
Throughout this assignment, use three-element numpy arrays to represent unit vectors, position vectors, separation vectors, and force vectors. In all cases, the three elements of each numpy array
will represent the (x, y, z) components of the vector. Make sure you are taking advantage of power of numpy arrays! Remember to be very clear and careful with units throughout your code!
1. Create a Python function that accepts an array representation of a vector ~a =(ax, ay, az)
and returns its magnitude a.
Test this function with a vector ~a =(1,2,3); comment on what the answer should be
(show the calculation you expect your function to do) and check that your function returns what you expect.
2. Create a Python function that accepts an array representation of a vector ~a =(ax, ay, az)
and returns its unit vector a.(This function must call your previously-created function).
Test this function with that same vector ~a =(1,2,3); comment on what the answer should be (show the calculation you expect your function to do) and check that your function returns what you expect. Also show that the magnitude of your unit vector is indeed unity.
3. Create a Python function that accepts two position vectors ~ri and ~rj , and returns the separation vector between them ~rij = ~rj ~ri
.
Test this function by calculating the separation vector between the positions of the Earth and the Sun above. Use your magnitude function to calculate the magnitude of the distance rij between these bodies. For the Earth-Sun system, comment on what the answer should be (you should be able to predict the answer for the magnitude without any calculations!) and check that your function returns what you expect.
4. Create a Python function that accepts two masses and the magnitude of the separation between them as input and returns the magnitude of the force as a float. This is the force magnitude, not the force vector.
For the Earth-Sun system, comment (generally) on what the answer should be and check that your function returns something reasonable.
5. Create a Python function that accepts two masses and two position vectors, and returns the full gravitational force vector F~ij acting on a particle. (This function must call some of your
previously-created functions).
Test your function by calculating the gravitational force on the Earth (particle 0) caused by the Sun (particle 1). Comment (generally) on what the answer should be and check that your function returns something reasonable. In particular, make sure you can explain the sign of each coordinate of your force vector.

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 Programming Questions!