%pylab inline
The data file is expected to consist of header information, followed by a series of rows containing equal numbers of data values.
# The balloon data has been downloaded from the web and saved as "balloon.dat"
# There are 138 rows of header information, so we skip these using the "skiprows" keyword argument
data = loadtxt("balloon.dat", skiprows=138)
# The balloon data is now loaded into a 2D numpy array
data
# Use slicing to select the minutes
# Select from every row,
mins = data[:, 0]
# Slice the seconds
secs = data[:, 1]
# Slice the temperature
temp = data[:, 5]
print mins
print secs
print temp
# Use numpy array operations to combine integer minutes and seconds into a single floating-point minutes
t = mins + secs/60.
Consider the function:
$g(x) = \left\{ \begin{array} \log(1 + x)/x & x \neq 1 \\ 1 & x = 1 \end{array}\right.$
Coding this function directly in Python leads to the graph below.
end = 10**-7
x = linspace(-end, end, 641)
y = where(x==0.0, 1.0, log(1 + x)/x)
xlim(-end, end)
plot(x, y)
end = 10**-15
x = linspace(-end, end, 641)
y = where(x==0.0, 1.0, log(1 + x)/x)
xlim(-end, end)
plot(x, y)
$x - \dfrac{x^2}{2} + \dfrac{x^3}{3} - R_4$, where $|R_4| < \dfrac{x^4}{4}$
which gives
$\dfrac{\log(1 + x)}{x} = 1 - \dfrac{x}{2} + \dfrac{x^2}{3} - Q$, where $|Q| < \dfrac{x^3}{4}$
This approximation is as accurate as we need if $|Q| < $ machine epsilon ($\sim 10^{-16}) \Rightarrow x < 7 \times 10^{-6}$
end = 10**-7
x = linspace(-end, end, 641)
y = where(x==0, 1.0, log(1+x)/x)
xlim(-end, end)
plot(x, y)
plot(x, 1 - x/2. + (x**2)/3., 'r')