#example 2.1
import matplotlib.pyplot as plt
import numpy
import math
Distance=[2.5,5,7.5,10,15,20,25,30,35,40,50];
Time=(10**(-3))*numpy.array([11.2,23.3,33.5,42.4,50.9,57.2,64.4,68.6,71.1,72.1,75.5])
#part1
distance=5.25; # in meter
time=23e-3; # in second
v1=distance/time;
print round(v1,2),"is speed in m/s"
#part2
distance=11; # in meter
time=13.5e-3;# in second
v2=distance/time;
print round(v2,2)," is speed in m/s"
#part3
distance=14.75;# in meter
time=3.5e-3;# in second
v3=distance/time;
print round(v3,2),"speed in m/s"
plt.plot(Distance,Time);
plt.title("distance vs time")
plt.xlabel("Distance in m")
plt.ylabel("time in s")
plt.show()
#part4
xc=10.4;
Ta=65e-3;
Z1=1/2.0*math.sqrt((v2-v1)/(v2+v1))*xc;
print round(Z1,2)," is thickness of layer 1 in m"
Z2=1/2.0*(Ta-2*Z1*math.sqrt(v3**2-v1**2)/v3/v1)*v3*v2/math.sqrt(v3**2-v2**2);
print round(Z2,2)," is thickness of layer 2 in m"
# the answers are slightly different in textbook due to approximation while here answers are precise