CPSC120A
Fundamentals of Computer Science I

Scientific Assignment 2

Use Python for physics.

Gravity is one of the fundamental forces of nature. No matter what we try, we are pretty much always under the affect of gravity from some body. As a matter of fact, based on the laws of physics we are constantly under the affect of gravity from an almost uncountable number of items. For this assignment, you will compute the force of gravity between various elements.


Details

The gravitational force between two objects can be computed using the equation:

F = G × M1 × M2 / r2

Where the gravitational constant G = 6.673 × 10-11, M1 and M2 are the masses (in kg) of the objects in question, and r is the distance (in meters) between the centers of mass of the two objects.

Write a function called compute_gravitational_force(mass1, mass2, distance), which will compute this force. This function takes 3 floating point values: the masses of the two elements, and the distance beween the two items (in meters). This function should return the gravitational force, labeled appropriately.

You will also need functions to convert from kilometers to meters and from pounds to kilograms. Make sure you test these three functions thoroughly before you continue on.

The Sun has a mass of roughly 1.981 × 1030 kg. Its mass is over 300 times that of the Earth (5.97 × 1024 kg). Compute the gravitational force between the Sun and the Earth, assuming the average distance between them is 147 million km.

The Earth's orbit is not perfectly circular. The elliptical nature of the orbit causes the distance between the Earth and the Sun to vary by about 5 million km over the course of the year (about 2.5 million km in either direction). Write a new function that returns how this affects the gravitational force, by computing the gravitational force for every 1000 km increment in that range.

You can also use this equation to compute the force of gravity that is acting upon you from the Earth. Look up the radius of the Earth, and plug in your weight into the above function. If you try some various weights, you could probably find a shorter equation to compute this same value. Write a new function that simply compute the force of gravity (on earth).


"Hacker" Prompt

  1. My Pancreas:

    My pancreas attracts every other
    Pancreas in the universe
    With a force proportional
    To the product of their masses
    And inversely proportional
    To the distance between them...

    "Weird Al" Yankovic in Pancreas

    Who would have thought that real physics would appear in such an absurd song? It's true, your pancreas does attract every other pancreas in the universe. The typical human pancreas weighs about 80 grams. Compute the attractive force between your pancreas and a person who is 1 meter away from you.

  2. Magnets, how do they work? One of the goals behind the "Grand Unified Theory" of Physics is to describe all four of the fundamental forces of the Standard Model using one single force equation. While it might seem like a silly thing to do, we know that the equations for the electro-magnetic forces and gravitational forces are very similar:

    F = k × q1 × q2 / r 2
    Where q1 and q2 are the charges of two electro-magnetic particles (measured in Coulombs), r is the distance between them (measured in meters), and k is Coulombs constant defined as :
    k ≈ 9 × 109 N ˙ m2 / C2

    Write a function to also compute this force as well. Research the electro-magnetic force, and use your function to compute some well known magnetic forces.

Submission

Your code should conform to the course’s code conventions and will be graded according the the course’s programming assignment rubric. Submit your program as a .py file on the course Inquire page before class on Friday September 19th.