You are on page 1of 3

EXERCISE PYTHON FOR GEOPHYSICS

P4G-ESRBASC

A ball is thrown vertically up in the air from a height h0 above the ground at an initial velocity v0. Its
subsequent height h and velocity v are given by the equations

1
h = h0 + v0t − gt 2
2

v = v0 − gt

where g = 9.8 is the acceleration due to gravity in m/s2. Write a script that finds the height h and velocity
v at a time t after the ball is thrown. Start the script by setting h0 = 1.6 (meters) and v0 = 14.2 (m/s) and
have your script print out the values of height and velocity. Then use the script to find the height and
velocity after 0.5 seconds. Then modify your script to find them after 2.0 seconds.

P4G-IFRLOOP

Write a program that determines the day of the week for any given calendar date after January
1, 1900, which was a Monday. Your program will need to take into account leap years, which
occur in every year that is divisible by 4, except for years that are divisible by 100 but are not
divisible by 400. For example, 1900 was not a leap year, but 2000 was a leap year. Test that
your program gives the answers tabulated below.

P4G-EXRPLOT

The data file below shows data obtained for the displacement (position) vs. time of a falling
object, together with the estimated uncertainty in the displacement.

(a) Use these data to calculate the velocity and acceleration, together with their uncertainties
propagated from the displacement vs. time uncertainties. Be sure to calculate time arrays
corresponding the midpoint in time between the two displacements or velocities for the
velocity and acceleration arrays, respectively.
(b) In a single window frame, make three vertically stacked plots of the displacement, velocity,
and acceleration vs. time. Show the error bars on the different plots. Make sure that the
time axes of all three plots cover the same range of times (use sharex). Why do the
relative sizes of the error bars grow progressively greater as one progresses from
displacement to velocity to acceleration?

P4G-EPRFUNC

(a) Write a function that simulates the rolling of n dice. Use the NumPy function
random.random_integers(6), which generates a random integer between 1 and
6 with equal probability (like rolling fair dice). The input of your function should be the
number of dice thrown each roll and the output should be the sum of the n dice.

(b) "Roll" 2 dice 10,000 times keeping track of all the sums of each set of rolls in a list. Then
use your program to generate a histogram summarizing the rolls of two dice 10,000 times.
The result should look like the histogram plotted above. Use the matplotlib function hist
(see http://matplotlib.org/api/pyplot_summary.html) and set the number of bins in the
histogram equal to the number of different possible outcomes of a roll of your dice. For
example, the sum of two dice can be anything between 2 and 12, which corresponds to
11 possible outcomes. You should get a histogram that looks like the one below.

(c) Repeat part (b) using 3 dice and plot the resulting histogram.

discussion is allowed but

NO COPY PASTE

Prima Wira Kusuma Wardhani, S.Si., M.Sc.


Fittra Irwandhono, S.Si.

You might also like