Practice Problems

Lecture 16

Answer each number in a separate cell

Rename the notebook with your lastName and the lecture

ex. Cych_16

Turn this notebook into TritonEd by the end of class

In [1]:
import pandas as pd
import numpy as np

1. Linear regression

  • Read in the dataset Datasets/SpreadingRates/km_age.txt as a Pandas DataFrame
    • Each data point is the age and distance from the South Atlantic ridge crests to a particular magnetic anomaly. The ages (Ma) were published by Gradstein et al. (2004)
  • Plot the age against distance; use age as the x-axis. Label your figure

  • Calculate the spreading rate by using the function np.polyfit( ) and a linear fit

  • Evaluate the linear fit using np.polyval( )
  • Plot the best fit line as a red dashed line along with the data

2. Lambda functions

  • Write a lambda function that converts z to velocity
  • Write a second lambda function that converts mu to distance
  • Rewrite the code cell that follows to call your new functions
In [3]:
new_data=pd.read_csv('Datasets/redShiftDistance/mu_z.csv',header=1)

# function returns age in Ga for Ho
age_from_Ho= lambda Ho : 1e-9*3.09e19/(Ho*np.pi*1e7)

# convert z to velocity in 10^3 km/s (or 10^6 m/s)
c=3e8 # speed of light in m/s
new_data['velocity']=1e-6*c* \
    (((new_data.z+1.)**2-1.)/((new_data.z+1.)**2+1.)) # the formula for v from z (and c)
# convert mu to distance in 10^3 Mpc (a Gpc):
new_data['distance']=10.*(10.**((new_data['mu'])/5.))*1e-9 # convert mu to Gpc
# and filter for the closest objects
close_data=new_data[new_data.distance<0.7]

close_fit= np.polyfit(close_data['distance'],close_data['velocity'],1) # calculate the coefficients
close_modelYs=np.polyval(close_fit,close_data['distance']) # get the model values

age=age_from_Ho(close_fit[0]) # get a new age 
print (age)
16.8657555333

3. Polynomial fits

Certain isotopes are unstable and decay through radioactive decay. The formula for radioactive decay is:

$N= N_o \exp^{-\lambda T}$

$\lambda$ is the decay constant (the time for $N$ to decay to $1/\exp$ of the original value

$T$ is time

$N$ is the number of nuclei remaining after time $T$

$N_o$ is the original number or parent nuclei

The half-life ($t_{1/2}$) is the time for $N$ to decay to $N_o$/2. The formula is:

$t_{1/2} = \frac {ln 2}{\lambda}$

  • Write a lambda function to calculate radioactive decay. The decay constant, time, and initial parent should be supplied as parameters.
  • The half-life of radiocarbon is 5,730 yrs. Calculate the decay constant of radiocarbon
  • Assume that the the initial parent, $N_o$, is 1, and time ranges from 0 to 7 half-lives. Use your function to calculate radioactive decay for radiocarbon
  • Plot a curve of $N$ versus $T$
  • Calculate the best-fit polynomial to your curve.
  • Draw a red vertical line at the half-life of radiocarbon and a red horizontal line at .5.