\DefineExercise{E5-1_Main1}{

Consider the graph of the function $y=\sqrt{1-x^2}$ between $0$ and $1$:

\begin{tikzpicture}
\pgfset{declare function={f(\x)=sqrt(1-\x*\x);}}
  \begin{axis}[width=240, height =200, xmax=1, ymax=1, xmin=0, ymin=0, xlabel=$x$, ylabel=$y$, axis x line = middle, axis y line=middle]
%\addplot {0};
\addplot[smooth,samples=1000,domain=0:1,fill=black,pattern=custom north west lines,hatchspread=5pt] {f(x)}\closedcycle;
  \end{axis}
\end{tikzpicture}

What is the \emph{exact} area of the shaded portion?
}

\DefineExercise{E5-1_Main2}{
We're going to try to estimate the area under the parabola $y=1-x^2$ between $0$ and $1$:

\begin{tikzpicture}
\pgfset{declare function={f(\x)=1-\x*\x;}}
  \begin{axis}[width=240, height =200, xmax=1, ymax=1, xmin=0, ymin=0, xlabel=$x$, ylabel=$y$, axis x line = middle, axis y line=middle]
\addplot[smooth,samples=1000,domain=0:1,fill=black,pattern=custom north west lines,hatchspread=5pt] {f(x)}\closedcycle;
  \end{axis}
\end{tikzpicture}

\begin{enumerate}[label=(\alph*)]
\item Calculate the shaded area in the picture below:

\begin{tikzpicture}
\pgfset{declare function={f(\x)=1-\x*\x;}}
  \begin{axis}[width=240, height =200, xmax=1, ymax=1, xmin=0, ymin=0, xlabel=$x$, ylabel=$y$, axis x line = middle, axis y line=middle]
\addplot[smooth,samples=1000,domain=0:1] {1-x*x};
\addplot[smooth,samples=1000,domain=0:1, integral segments=4, integral max=0:1,fill=black,pattern=custom north west lines,hatchspread=5pt] {1-x*x};
%\RiemannLeft{0}{1}{4}{1-x*x};
  \end{axis}
\end{tikzpicture}

\pagebreak
\item Calculate the shaded area in the picture below:

\begin{tikzpicture}
\pgfset{declare function={f(\x)=1-\x*\x;}}
  \begin{axis}[width=240, height =200, xmax=1, ymax=1, xmin=0, ymin=0, xlabel=$x$, ylabel=$y$, axis x line = middle, axis y line=middle]
\addplot[smooth,samples=1000,domain=0:1] {1-x*x};
\addplot[smooth,samples=1000,domain=0:1, integral segments=8, integral max=0:1,fill=black,pattern=custom north west lines,hatchspread=5pt] {1-x*x};
  \end{axis}
\end{tikzpicture}

\item Are the estimates from the previous two parts larger or smaller than the actual value?

\item Calculate the shaded area in the picture below:

\begin{tikzpicture}
\pgfset{declare function={f(\x)=1-\x*\x;}}
  \begin{axis}[width=240, height =200, xmax=1, ymax=1, xmin=0, ymin=0, xlabel=$x$, ylabel=$y$, axis x line = middle, axis y line=middle]
\addplot[smooth,samples=1000,domain=0:1] {1-x*x};
\addplot[smooth,samples=1000,domain=0:1, integral segments=4, integral min=0:1,fill=black,pattern=custom north west lines,hatchspread=5pt] {1-x*x};
  \end{axis}
\end{tikzpicture}

\pagebreak
\item Calculate the shaded area in the picture below:

\begin{tikzpicture}
\pgfset{declare function={f(\x)=1-\x*\x;}}
  \begin{axis}[width=240, height =200, xmax=1, ymax=1, xmin=0, ymin=0, xlabel=$x$, ylabel=$y$, axis x line = middle, axis y line=middle]
\addplot[smooth,samples=1000,domain=0:1] {1-x*x};
\addplot[smooth,samples=1000,domain=0:1, integral segments=8, integral min=0:1,fill=black,pattern=custom north west lines,hatchspread=5pt] {1-x*x};
  \end{axis}
\end{tikzpicture}

\item Are the estimates from the previous two parts larger or smaller than the actual value?

 
 To make the estimate better, we could use even more rectangles:

\begin{tikzpicture}
\pgfset{declare function={f(\x)=1-\x*\x;}}
  \begin{axis}[width=240, height =200, xmax=1, ymax=1, xmin=0, ymin=0, xlabel=$x$, ylabel=$y$, axis x line = middle, axis y line=middle]
\addplot[smooth,samples=1000,domain=0:1] {1-x*x};
\addplot[smooth,samples=1000,domain=0:1, integral segments=25, integral min=0:1,fill=black,pattern=custom north west lines,hatchspread=5pt] {1-x*x};
  \end{axis}
\end{tikzpicture}

There are 25 rectangles in this picture. 

\item What is the area of the $7$th rectangle?

\item What is the area of the $12$th rectangle?

\item If $k$ is an integer between $1$ and $25$, what is the area of the $k$th rectangle?

Once again, we can use the left endpoint instead of the right endpoint.

\begin{tikzpicture}
\pgfset{declare function={f(\x)=1-\x*\x;}}
  \begin{axis}[width=240, height =200, xmax=1, ymax=1, xmin=0, ymin=0, xlabel=$x$, ylabel=$y$, axis x line = middle, axis y line=middle]
\addplot[smooth,samples=1000,domain=0:1] {1-x*x};
\addplot[smooth,samples=1000,domain=0:1, integral segments=25, integral max=0:1,fill=black,pattern=custom north west lines,hatchspread=5pt] {1-x*x};
  \end{axis}
\end{tikzpicture}

There are 25 rectangles in this picture (if you count the last one, which has height $0$).

\item What is the area of the $9$th rectangle?

\item What is the area of the $15$th rectangle?

\item If $k$ is an integer between $1$ and $25$, what is the area of the $k$th rectangle?

\item Write the area in these rectangles using $\Sigma$ notation.

\item Use the algebra rules for $\Sigma$ notation to calculate the are in these 25 rectangles.

\item Based on this estimate, estimate the average value of the function $1-x^2$ (using the definition of the average value of a function).
\end{enumerate}
}

\DefineExercise{E5-1_Main3}{
  \begin{enumerate}[label=(\alph*)]
  \item According to the definition of the average value of a function, what is the average value of $f(x)=2$ on the interval $[-1,1]$?
  \item Does that answer make sense?  Why or why not?
  \item According to the definition of the average value of a function, what is the average value of $f(x)=x+1$ on the interval $[-1,1]$?
  \item Does that answer make sense?  Why or why not?
  \end{enumerate}
}

\DefineExercise{E5-1_Main4}{
 When a patient has emphysema, a doctor needs to measure the average lung capacity.  Using a spirometer, the doctor measures the volume of air in the patient's lungs for $2$ seconds and finds that the volume is given by $V(t)=1-\cos\frac{\pi t}{2}$:

\begin{tikzpicture}
  \begin{axis}[width=240, height =200, xmax=2, ymax=2, xmin=0, ymin=0, xlabel=$t$, ylabel=$V(t)$, axis x line = middle, axis y line=middle]
\addplot[smooth,samples=1000,domain=0:2,fill=black,pattern=custom north west lines,hatchspread=5pt] {1-cos(pi*x /2 r)}\closedcycle;
  \end{axis}
\end{tikzpicture}

    \begin{enumerate}[label=(\alph*)]
    \item Estimate the area under this curve using four rectangles.
\item Use your estimate of the area to estimate the average value.
\item Is your estimate an overestimate or underestimate?
    \end{enumerate}
}

\DefineExercise{E5-1_Main5}{
There are many rules more complicated than the left and right endpoints we could use---for instance, we could use the midpoint.


\begin{tikzpicture}
\pgfset{declare function={f(\x)=1-(\x-1)*(\x-1);}}
  \begin{axis}[width=240, height =200, xmax=2, ymax=1, xmin=0, ymin=0, xlabel=$x$, ylabel=$y$, axis x line = middle, axis y line=middle]
\addplot[smooth,samples=1000,domain=0:2] {f(x)};
\addplot[smooth,samples=1000,domain=0:2, integral segments=6, integral mid=0:2,fill=black,pattern=custom north west lines,hatchspread=5pt] {f(x)};
  \end{axis}
\end{tikzpicture}

\begin{enumerate}[label=(\alph*)]
\item Express the shaded area using $\Sigma$ notation.
\item Calculate the shaded area any way you want.
\end{enumerate}
}


\DefineExercise{E5-1_Main6}{
\begin{enumerate}[label=(\alph*)]
\item Draw a function where the left endpoint rule \emph{overestimates} the area.
\item Draw a function where the left endpoint rule \emph{underestimates} the area.
\item Draw a function where the right endpoint rule \emph{overestimates} the area.
\item Draw a function where the right endpoint rule \emph{underestimates} the area.
\item Do these examples have anything to do with the second derivative of the function?
\end{enumerate}
}

\DefineExercise{E5-2_WarmUp1}{
  \begin{enumerate}[label=(\alph*)]
\item Rewrite the sum $\sum_{k=0}^{4}\cos\frac{k\pi}{2}$ without sigma notation.
\item Rewrite $1+3+5+7+9+11$ with sigma notation.
  \end{enumerate}
}

\DefineExercise{E5-2_WarmUp2}{
Use the algebra rules for finite sums to evaluate these sums:
  \begin{enumerate}[label=(\alph*)]
  \item $\sum_{k=1}^42k^2$
\item $\sum_{k=1}^84k+3k^2$
\item $\sum_{k=1}^n5k^3-2k$
  \end{enumerate}
}


\DefineExercise{E5-2_Main1}{
Consider the sum $\sum_{k=1}^{100}(A+kd)$.
  \begin{enumerate}[label=(\alph*)]
  \item If you expanded this to a sum without sigma notation, which variables would still appear in that expression?
\item Use the algebra rules for finite sums to evaluate this sum.
  \end{enumerate}
}


\DefineExercise{E5-2_Main3}{
Your friend suggests that sums should follow a product rule as well:
  \begin{quote}
    $\sum_{k=1}^na_kb_k=(\sum_{k=1}^na_k)(\sum_{k=1}^nb_k)$.
  \end{quote}
How could you convince your friend that they are wrong?
}

\DefineExercise{E5-2_Main4}{
Last class we saw this attempt to estimate for the area under the curve $y=1-x^2$ between $0$ and $1$ using 25 rectangles:

\begin{tikzpicture}
\pgfset{declare function={f(\x)=1-\x*\x;}}
  \begin{axis}[width=240, height =200, xmax=1, ymax=1, xmin=0, ymin=0, xlabel=$x$, ylabel=$y$, axis x line = middle, axis y line=middle]
\addplot[smooth,samples=1000,domain=0:1] {1-x*x};
\addplot[smooth,samples=1000,domain=0:1, integral segments=25, integral max=0:1,fill=black,pattern=custom north west lines,hatchspread=5pt] {1-x*x};
  \end{axis}
\end{tikzpicture}

\begin{enumerate}[label=(\alph*)]
\item Express the shaded area as a sum using sigma notation.
\item Evaluate this sum.
\item Suppose that instead of using 25 rectangles, we use $n$ rectangles.  Express the area covered by $n$ rectangles using sigma notation.
\item Evaluate this sum to an expression which doesn't use sigma notation.
\item Take the limit as $n\rightarrow\infty$.
\end{enumerate}
}


\DefineExercise{E5-2_Main5}{
Here are two more examples:

\hspace{-.5in}
\begin{tikzpicture}
\pgfset{declare function={f(\x)=-\x*\x/4+\x+1;}}
  \begin{axis}[width=240, height =200, xmax=4, ymax=3, xmin=2, ymin=0, xlabel=$x$, ylabel=$-\frac{x^2}{4}+x+1$, axis x line = middle, axis y line=middle]
\addplot[smooth,samples=1000,domain=2:4] {f(x)};
\addplot[smooth,samples=1000,domain=2:4, integral segments=10, integral max=2:4,fill=black,pattern=custom north west lines,hatchspread=5pt] {f(x)};
  \end{axis}
\end{tikzpicture}
\begin{tikzpicture}
\pgfset{declare function={f(\x)=-3*\x*\x/4+3*\x;}}
  \begin{axis}[width=240, height =200, xmax=4, ymax=3, xmin=2, ymin=0, xlabel=$x$, ylabel=$-\frac{3x^2}{4}+3x$, axis x line = middle, axis y line=middle, ylabel style={at=(current axis.above origin), anchor=north east}]
\addplot[smooth,samples=1000,domain=2:4] {f(x)};
\addplot[smooth,samples=1000,domain=2:4, integral segments=10, integral max=2:4,fill=black,pattern=custom north west lines,hatchspread=5pt] {f(x)};
  \end{axis}
\end{tikzpicture}


\begin{enumerate}[label=(\alph*)]
\item Express the shaded area in the picture on the left as a sum using sigma notation.
\item Remembering that rectangles below the curve will count as ``negative area'', express the shaded area in the picture on the right as a sum using sigma notation.
\item Which group of rectangles gives a better estimate for the actual area under the curve?  What property of the functions causes this?
\end{enumerate}
}


\DefineExercise{E5-2_Main6}{
Suppose that we use rectangles to estimate the area under the curve $x^2+7$ between $1$ and $3$.
  \begin{enumerate}[label=(\alph*)]
  \item Express the area covered by $n$ rectangles using the \emph{left} endpoint for the height using sigma notation.
\item Evaluate this sum to an expression which doesn't use sigma notation.
\item Take the limit as $n\rightarrow\infty$.
  \end{enumerate}
}


\DefineExercise{E5-3_WarmUp1}{
Suppose $g$ and $h$ are integrable functions such that $\int_0^3 g(x) dx=2$, $\int_2^3 h(x) dx=1$, and $\int_0^2 g(x)dx=-1$.

  \begin{enumerate}
  \item What is $\int_2^3 g(x) dx$?
\item What is $\int_2^3 g(x)+h(x) dx$?
\item What is $\int_2^2 g(x) dx$?
\item What is $\int_2^3 2g(x)-4h(x) dx$?
\item What is the average value of $g(x)$ on the interval $[0,3]$?
  \end{enumerate}
}


\DefineExercise{E5-3_WarmUp2}{
Consider the following strange function:

  \begin{tikzpicture}
  \begin{axis}[width=240, height =200, xmax=4, ymax=2, xmin=0, ymin=0, xlabel=$x$, ylabel=$u(x)$, axis x line = middle, axis y line=middle]
\addplot[smooth,samples=1000,domain=0:1] {2*x};
\addplot[smooth,samples=1000,domain=1:2] {2-sqrt(.25-(x-1.5)*(x-1.5))};
\addplot[smooth,samples=1000,domain=2:3] {4-x};
\addplot[smooth,samples=1000,domain=3:4] {1};
  \end{axis}
\end{tikzpicture}

What is $\int_0^4 u(x) dx$?
}

\DefineExercise{E5-3_Main1}{
 Consider the integrable function $f(x)$ below:

  \begin{tikzpicture}
  \begin{axis}[width=180, height =160, xmax=2, ymax=2.1, xmin=-2, ymin=0, xlabel=$x$, ylabel=$f(x)$, axis x line = middle, axis y line=middle]
\addplot[smooth, samples=1000, domain=-2:1,fill=black,pattern=custom north west lines,hatchspread=5pt] {(x+2)*((3*x/8-1)*(x+1)+1)+1}\closedcycle;
\addplot[smooth, samples=1000, domain=1:2,fill=black,pattern=crosshatch] {(x+2)*((3*x/8-1)*(x+1)+1)+1}\closedcycle;
\end{axis}

  %   \tgraph{$x$}{-2}{2}{-1}{$f(x)$}{0}{2}{1};
  %   \filldraw[pattern=custom north west lines,hatchspread=5pt] (-2,1) -- plot[smooth,samples=100,domain=-2:1]({\x},{(\x+2)*((3*\x/8-1)*(\x+1)+1)+1}) -- (1,0) -- (-2,0) --cycle;
  %   \filldraw[pattern=crosshatch] (1,0) -- plot[smooth,samples=100,domain=1:2]({\x},{(\x+2)*((3*\x/8-1)*(\x+1)+1)+1}) -- (2,0) -- cycle;
 \end{tikzpicture}

  \begin{enumerate}
  \item Express the area shaded like 
    \begin{tikzpicture}[scale=0.5]
      \filldraw[pattern=custom north west lines,hatchspread=5pt] (0,1)--(0,0)--(1,0)--(1,1)--cycle;
    \end{tikzpicture}
as a definite integral.  %The value of this integral is $\frac{123}{32}$.
  \item Express the area shaded like 
    \begin{tikzpicture}[scale=0.5]
      \filldraw[pattern=crosshatch] (0,1)--(0,0)--(1,0)--(1,1)--cycle;
    \end{tikzpicture}
as a definite integral.%  The value of this integral is $\frac{79}{96}$.
\item Express the combined shaded area as a definite integral.
\item Write an equation relating these three integrals.
\item Which rule from Table 5.4 on page 317 does this represent?
  \end{enumerate}
}


\DefineExercise{E5-3_Main2}{
Without doing any calculations (but feel free to draw a picture), which is larger, $\int_1^2 x^2 dx$ or $\int_1^2 x\, dx$?
}

\DefineExercise{E5-3_Main5}{
We're going to put together everything we've seen to calculate $\int_1^3 x^2/2-x+1\, dx$.

\begin{tikzpicture}
\pgfset{declare function={f(\x)=\x*\x/2-\x+1;}}
  \begin{axis}[width=240, height =200, xmax=3, ymax=3, xmin=1, ymin=0, xlabel=$x$, ylabel=$x^2/2-x+1$, axis x line = middle, axis y line=middle]
\addplot[smooth,samples=1000,domain=1:3,fill=black,pattern=custom north west lines,hatchspread=5pt] {f(x)}\closedcycle;
  \end{axis}
\end{tikzpicture}

\begin{enumerate}[label=(\alph*)]
\item As a warm up, estimate the area under this curve using four rectangles
\item Now calculate $\int_1^3 x^2/2-x+1\, dx$.
\texttt{  \begin{enumerate}[label=(\roman*)]
  \item Suppose we divide the area under the curve into $n$ rectangles, where $n$ is some big number.  What is the width of each rectangle?
  \item When there are $n$ rectangles, what is the height of the $1$st rectangle?  What about the $5$th?  The $k$th?
  \item Express the area under $n$ rectangles using $\Sigma$ notation.
  \item Use the rules for $\Sigma$ notation to calculate this sum.
  \item Take the limit as $n\rightarrow\infty$.  The value of this limit is the definite intgral.
  \end{enumerate}
}\end{enumerate}
}


\DefineExercise{E5-3_Main3}{
We want to check that $\int_0^1 x^{-2} dx$ is actually infinite.  We will do this by showing that $\int_0^1 x^{-2} dx\geq N$ for all $N$.


  \begin{tikzpicture}
  \begin{axis}[width=240, height =200, xmax=4, ymax=40, xmin=0, ymin=0, xlabel=$x$, ylabel=$1/x^2$, axis x line = middle, axis y line=middle]
\addplot[smooth, samples=1000, domain=0.1:4] {1/(x*x)}\closedcycle;
\end{axis}
    % \tgraph{$x$}{0}{1}{1}{$y$}{0}{4}{1};
    % \draw[pattern=custom north west lines,hatchspread=5pt] plot[smooth,samples=100,domain=0.5:1]({\x},{1/(\x*\x)}) --(1,0)--(0,0)--(0,4) ;
%  \foreach \x in {0,1,...,24} 
 %    \draw[pattern=custom north west lines,hatchspread=5pt] (2*\x/25,0) -- ({2*(\x+1)/25},0)--({2*(\x+1)/25},{4*(\x+1)*(\x+1)/(25*25)}) -- (2*\x/25,{4*(\x+1)*(\x+1)/(25*25)})--cycle;
\end{tikzpicture}

  \begin{tikzpicture}
  \begin{axis}[width=240, height =200, xmax=1, ymax=4, xmin=0, ymin=0, xlabel=$x$, ylabel=$1/x^2$, axis x line = middle, axis y line=middle]
\addplot[smooth, samples=1000, domain=0:1,fill=black,pattern=custom north west lines,hatchspread=5pt] {min(4,1/(x*x))}\closedcycle;
\end{axis}
    % \tgraph{$x$}{0}{1}{1}{$y$}{0}{4}{1};
    % \draw[pattern=custom north west lines,hatchspread=5pt] plot[smooth,samples=100,domain=0.5:1]({\x},{1/(\x*\x)}) --(1,0)--(0,0)--(0,4) ;
%  \foreach \x in {0,1,...,24} 
 %    \draw[pattern=custom north west lines,hatchspread=5pt] (2*\x/25,0) -- ({2*(\x+1)/25},0)--({2*(\x+1)/25},{4*(\x+1)*(\x+1)/(25*25)}) -- (2*\x/25,{4*(\x+1)*(\x+1)/(25*25)})--cycle;
\end{tikzpicture}

Both graphs are showing $1/x^2$; the first one gives a bigger picture, and the second one is zoomed in to only show that part where $x$ is between $0$ and $1$ and $y$ is between $0$ and $4$.  Don't get confused by the fact that the picture is cut off: as $x$ gets closer to $0$, $1/x^2$ gets big, so the region underneath the curve $1/x^2$ includes things above $y=4$.

  \begin{enumerate}[label=(\alph*)]
\item Consider the box underneath the curve $1/x^2$ which has width $1$ and is as tall as possible.  Draw this box in the second picture above and calculate its area.
\item Consider the box underneath the curve $1/x^2$ which has width $1/2$ and is as tall as possible.  Draw this box in the picture above and calculate its area.
\item What is the area of the largest possible box which fits underneath the curve $1/x^2$ and has width $1/4$?
\item Find a box contained underneath the curve $1/x^2$ with area $\geq N$ for an arbitrary $N$?
\item Explain why this means $\int_0^1 x^{-2} dx$ must be infinite.
  \end{enumerate}

In 104 you'll see that some curves can have finite area even though they approach infinity.  For instance, you'll see that $\int_0^1 x^{-1/2} dx=2$.
}

\DefineExercise{E5-3_Main4}{
We can view the definite integral as a function itself.

  \begin{enumerate}
  \item Define a function $F(t)=\int_0^t x\ dx$?  Use geometry to express $F(t)$ as a polynomial.

\texttt{
Draw a picture of the area represented by the integral $\int_0^t x\ dx$.
}

  \item Define a function $G(t)=\int_2^t x\ dx$?  Use geometry to express $G(t)$ as a polynomial.
  \end{enumerate}
}