Homework 3

[124]:
from IPython.display import HTML

HTML('''
<center>
<h4>The Definite Integral as a Limit(1966)</h4>
<iframe src="https://player.vimeo.com/video/101832466?title=0&byline=0&portrait=0"
width="700" height="394" frameborder="0" webkitallowfullscreen mozallowfullscreen
allowfullscreen></iframe>
</center>
<p>Please watch the video above.  Can you find a better alternative -- poor video is getting old...</p>
''')
[124]:

The Definite Integral as a Limit(1966)

Please watch the video above. Can you find a better alternative -- poor video is getting old...

  1. Use our formulas from class to evaluate the following sums:

  2. \[\sum_{i = 1}^{20} 100(i^2 - 5i + 1)\]
  3. \[\sum_{i = 1}^{50} (i^2 - 10i)\]
  1. Use Riemann sums to approximate the area under the curve for the given function on given interval:
  2. \(n = 4\) for \(f(x) = \frac{1}{x-1}\) on \([2, 4]\)
  3. \(n = 4\) for \(f(x) = \cos(\pi x)\) on \([0, 2\pi]\).
  4. \(n = 8\) for \(f(x) = x^2 - 2x + 1\) on \([0, 2]\).
  1. Let \(r_j\) denote the total rainfall in New York City on the \(j\)th day of the year in 2020. Interpret
\[\sum_{j = 1}^{31} r_j\]
  1. Below is the data from our Central Park weather station. We have isolated the Precipiation column, and plotted both it and the total precipitation for the month of January in the year 2020. How could we make the second plot using the first? (HINT: Look up what the .cumsum() method does in Pandas, or just think about what we’re doing in class!)
<tr style="text-align: right;">      <th></th>      <th>DATE</th>      <th>PRCP</th>    </tr>  </thead>  <tbody>    <tr>      <th>0</th>      <td>1870-01-01</td>      <td>0.08</td>    </tr>    <tr>      <th>1</th>      <td>1870-01-02</td>      <td>1.18</td>    </tr>    <tr>      <th>2</th>      <td>1870-01-03</td>      <td>0.00</td>    </tr>    <tr>      <th>3</th>      <td>1870-01-04</td>      <td>0.00</td>    </tr>    <tr>      <th>4</th>      <td>1870-01-05</td>      <td>0.00</td>    </tr>  </tbody></table>

e1959d73418a4432a796b009e2c2e21b

  1. Below is a plot of the average weekly earnings by americans according to the Bureau of Labor Statistics. How can you use this plot to determine the average wage from 2009 to 2019 measured each quarter. How can you use this graph to determine the average weekly earning over the 10 year period?
<img src = 'images/a3p4.png'>
</center>
  1. Useful summations:
  • AVERAGE:

    \[\frac{1}{n} \sum_{i = 1}^n x_i\]
  • VARIANCE:

    \[\frac{1}{n} \sum_{i = 1}^n (x_i - \mu)^2\]

    where \(\mu\) is the mean of the data

Use these formulas to compute the mean and variance of the datasets below. What does the variance explain about a dataset based on your observations?

  • Dataset 1: [5, 5, 5, 4, 4]
  • Dataset 2: [1, 3, 5, 7, 9]
  1. Recall our power rule and evaluation method for definite integrals from class today. Use this to evaluate the following definite integrals. For an extra challenge, try to draw a plot and fill in the area using the example below.
  • \(\int_{-1}^2 (x^2 - 3x) dx\)
  • $:nbsphinx-math:int_{-2}3(x2 + 3x - 5)dx $
  • \(\int_{1}^2 x^9 dx\)
  • $:nbsphinx-math:int_{1}^2 \frac{2}{x^3} dx $
[135]:
%matplotlib inline
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
[142]:
x = np.linspace(-1, 2, 1000) #define the domain
def f(x): return x**2 + 3*x  #define the function
plt.plot(x, f(x))            #plot the function
plt.fill_between(x, f(x),    #fill in the color
                 color = 'orange', alpha = 0.4)
plt.grid()                  #turn on the grid
plt.title('Area under $f(x) = x^2 - 3x$ on [-1, 2]', loc = 'left'); #make the title
../_images/notebooks_07_hw3_12_0.png
  1. Integration has long been an important part of the freshman calculus sequence at major universities. So much so that MIT even holds a regular integration bee where students solve challenging integration problems. Solving these problems was also an important part of early Artificial Intelligence work at MIT, namely the SAINT computer program that was written to solve symbolic integration problems. Please read a few pages of the work here. What do you think about this? Should we do things if we know there are machines that can do them better? What does this mean for math class!
  1. How could we use our ideas around area to think about computing the volume of the shape shown below? Describe a procedure for doing so.

529751d09c2b4e0e9d96041b1190f7ae

[ ]:
# %matplotlib inline
# import pandas as pd
# df = pd.read_csv('data/2017018.csv')
# df['DATE'] = pd.to_datetime(df['DATE'])

# precipitation_data = df.loc[df['DATE'].dt.year == 2020, ['DATE', 'PRCP']]

# precipitation_data.set_index('DATE', inplace = True)

# import matplotlib.pyplot as plt
# fig, ax = plt.subplots(nrows = 1, ncols = 2, figsize = (16, 7))
# precipitation_data.plot(linestyle = '--', ax = ax[0], grid = True, title = 'Precipitation in Central Park')
# precipitation_data.cumsum().plot(linestyle = '--', ax = ax[1], grid = True, title = 'Accumulated Precipitation in Central Park');
# plt.savefig('images/a3p3.png')
[165]:
# hourly_earnings_bls = pd.read_excel('data/bls.xlsx', skiprows = 19,  columns = ['id', 'year', 'quarter', 'value']).iloc[:, 1:4]

# hourly_earnings_bls['Year'] = pd.to_datetime(hourly_earnings_bls['Year'], format = '%Y').dt.year

# hourly_earnings_bls['Value'].plot(linestyle = '--', figsize = (15, 5))
# plt.grid()
# plt.title('Weekly Earnings by Quarter\n2009 - 2019', loc = 'left');
# plt.savefig('images/a3p4.png')
[164]:
# from mpl_toolkits.mplot3d import Axes3D
# # setup the figure and axes
# fig = plt.figure(figsize=(8, 6))
# ax1 = fig.add_subplot(projection='3d')


# # fake data
# _x = np.arange(4)
# _y = np.arange(5)
# _xx, _yy = np.meshgrid(_x, _y)
# x, y = _xx.ravel(), _yy.ravel()

# top = x**2 + y
# bottom = np.zeros_like(top)
# width = depth = 1

# ax1.bar3d(x, y, bottom, width, depth, top, shade=True)
# ax1.set_title('A 3D Shape');
# plt.savefig('images/a3p9.png')
[ ]: