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 with mtimes kg and the Sun is particle with
mtimes kg Lets put these at initial x y z positions of ~r AU for
the Earth and ~r AU for the Sun.
Throughout this assignment, use threeelement 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!
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 ; 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.
Create a Python function that accepts an array representation of a vector ~a ax ay az
and returns its unit vector aThis function must call your previouslycreated function
Test this function with that same vector ~a ; 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.
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 EarthSun 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.
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 EarthSun system, comment generally on what the answer should be and check that your function returns something reasonable.
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
previouslycreated functions
Test your function by calculating the gravitational force on the Earth particle caused by the Sun particle 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
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
