From charlesreid1

 
(18 intermediate revisions by the same user not shown)
Line 1: Line 1:
=Background=
=Read Before You Begin=


When might we need to evaluate an integral with data?
Before you begin with this worksheet, let's talk about what it will cover.


Numerical routine to integrate two functions and find a centroid - Magrab p. 154 (uses quadc() routine)
This worksheet is intended to answer the following questions: How do we evaluate integrals with a computer? When do we evaluate integrals with computers?


Expectations:
==Student expectations==
* Answers with complete sentences
* Some analytical work, some numerical work
* Final answers in report!
* Plot/chart to answer question


=PowerPoint Problem Setup=
You will submit a one-page report that answers each of the questions.


Explanation of numerical integration background, equation derivation
You will need to do some analytical work, and some numerical work. You will need to show your work for both kinds of questions.


Cover the questions
If a question asks for a plot or a chart, attach it to your report and refer to it in your answer.


Cover strategy, writing out what to do before implementing, how to implement in a spreadsheet
Answer questions with complete sentences.


Spend a day working in a computer lab
==Problem setup==
 
(Essential information is on handout, but go through it with board/slides/etc)
 
Numerical integration: background
 
Equation derivation: referring back to introduction to integrals, rectangle approximations, then through linear and quadratic approximations
 
Cover each question, cover strategy and writing out before implementing, how to implement in spreadsheet
 
Spend one day working in computer lab


=Worksheet Content=
=Worksheet Content=


Simpson's Rule to approximate the integral of a function,
==Instructions==
 
The following worksheet will introduce you to numerical integration techniques that can be implemented in a spreadsheet program like Microsoft Excel or Google Sheets.
 
Read through each section of the worksheet carefully. It contains the information you need to successfully implement Simpson's Rule in a spreadsheet.
 
You will submit a one-page report that answers each question at the end of the worksheet. Answer each question with complete sentences. This assignment is due in class on (date).
 
==Numerical Integration==
 
Let's start with a review of some numerical integration techniques we learned early on in the course: the left-hand, right-hand, and midpoint rules. These use constants to approximate a function in order to integrate it. We'll then review the Trapezoid Rule and Simpson's Rule, which use lines and quadratics, respectively, to improve the numerical approximation.
 
In each case, we're interested in approximating the integral of a function,  
 
<math>
I = \int_{a}^{b} f(x) dx
</math>
 
We can approximate this integral by splitting up the interval  into N sub-intervals, build rectangular strips, and compute their area to approximate the integral. The width of each sub-interval is called the step size  is related to the number of sub-intervals N and the limits of integration via the formula:


<math>
<math>
I = int_{a}^{b} f(x) dx
\Delta x = \frac{b-a}{N}
</math>
</math>


We can approximate this by splitting up the interval into sub-intervals, constructing strips, and approximating the area of each strip
This partitioning, as applied to a function, is shown in the figure on the right. There are N sub-intervals. The behavior of the function between the points <math>f(x_i)</math> depends on the numerical integration technique being used.
 
[[Image:SimpsonsRule1.jpg|500px]]


==Left Hand, Right Hand, and Midpoint Rules==
==Left Hand, Right Hand, and Midpoint Rules==


Chapter 5, first introduction to integration: we explored the left-hand, right-hand, and midpoint rules.
The left-hand, right-hand, and midpoint rules approximate the behavior of the function as a constant over the interval . Recall that we covered these when we were first introduced to the topic of integration. The constant function has one unknown parameter (y=c), and therefore requires one function evaluation.


These use a constant function. 1 parameter, 1 function evaluation.
[[Image:SimpsonsRule2.jpg|500px]]
 
[[Image:SimpsonsRule3.jpg|500px]]


==Trapezoid Rule==
==Trapezoid Rule==


Trapezoid rule: extends the technique by approximating with a line. 2 parameters, 2 function evaluations. 1 rectangle strip.
The Trapezoid Rule uses a line to approximate the behavior of the function (thus turning the “approximating rectangle” into an “approximating trapezoid”). This has two unknowns and requires the function to be evaluated at two points (see Fig. X). The trapezoid rule approximates the area as:


<math>
<math>
Line 45: Line 73:
</math>
</math>


Recurrence relation:
This formula may also be easier to program as a recurrence relation:


<math>
<math>
A_j = A_{j-1} + \frac{\Delta x}{2} \left( y_{j-1} + y_{j} \right)
A_j = A_{j-1} + \frac{\Delta x}{2} \left( y_{j-1} + y_{j} \right)
</math>
</math>
To approximate the total area, simply sum all of the <math>A_i</math> terms.
[[Image:SimpsonsRule4.jpg|500px]]


==Simpson's Rule==
==Simpson's Rule==


Simpson's Rule: extension to quadratic polynomial approximation. 3 parameters, 3 function evaluations. 2 rectangle strips.
Simpson's Rule uses a polynomial to approximate the behavior of the function between points and better approximate its integral. The approximating polynomial has three coefficients (three unknowns) and requires three function evaluations. Because Simpson's Rule requires the function at three points (two intervals), it operates two intervals at a time, and therefore Simpson's Rule requires an even number of intervals N.


For the simplest case of two intervals, Simpson's Rule is given by:
If we consider the simplest case of Simpson's Rule, with only two intervals, the area under the curve can be approximated using the formula:


<math>
<math>
Line 64: Line 96:


<math>
<math>
A = \Delta x \left( \frac{1}{3} y_0 + \frac{4}{3} y_1 + \frac{2}{3} y_2 + \frac{4}{3} y_3 + \dots + \frac{4}{3} y_{2k-1} + \frac{2}{3} y_{2k} + \dots + \frac{4}{3} y_{N-3} + \frac{2}{3} y_{N-2} + \frac{4}{3}y_{N-1} + \frac{1}{3} y_{N} \right)
</math>
Similarly, a recurrence relation that's easier to program is:


<math>
A_{2n} = A_{2(n-1)} + \Delta x \left( \frac{1}{3} y_{2n-2} + \frac{4}{3} y_{2n-1} + \frac{1}{3} y_{2n} \right)
</math>
</math>
To approximate the total area, simply sum all of the <math>A_i</math> terms.
Simpson's Rule fits a polynomial of degree 2 every three data points (two sub-intervals) and approximates the real function  with a set of polynomials . Therefore, Simpson's Rule is exact when  is a polynomial of degree 2 or less.
[[Image:SimpsonsRule5.jpg|500px]]
=Worksheet Questions for Calculus 2=
On a separate sheet of paper, answer each of the following questions with a complete sentence. Please be considerate of the environment – do not print out your spreadsheets.
Consider the following integral for the questions below:
<math>
I = \int_{0}^{40} 2 + \cos{( 2 \sqrt{x} )} dx
</math>
==Question 1==
Create a new worksheet using a spreadsheet program. Use it to approximate the value of the integral I using Simpson's Rule with N = 10 subintervals. Report the absolute error  in scientific notation. Report the relative error  as a percentage.
==Question 2==
In a new worksheet, approximate the value of the integral I using Simpson's Rule with N = 50 subintervals. Report the absolute error  in scientific notation. Report the relative error as a percentage.
==Question 3==
In a new worksheet, approximate the value of the integral I using Simpson's Rule with N = 100 subintervals. Report the absolute error  in scientific notation. Report the relative error as a percentage.
==Question 4==
We would expect that the error  would be a function of the step size , . Determine what the form of the functional relationship is by plotting  vs  for the cases above. What is the functional form? Some examples to consider:
<math>
\epsilon \sim \Delta x
</math>
<math>
\epsilon \sim \Delta x^n
</math>
<math>
\epsilon \sim e^{\Delta x}
</math>
<math>
\epsilon \sim \ln{(\Delta x)}
</math>
==Extra Credit==
Verify, using the substitution <math>u^2 = 4x</math>, that the indefinite integral is given by:
<math>
\int 2 + \cos{(2 \sqrt{x})} dx = 2x + \sqrt{x} \sin{(2 \sqrt{x})} - \frac{ \cos{(2 \sqrt{x})} }{ 2 } + C
</math>
=References=
=Flags=
{{WorksheetFlag}}

Latest revision as of 20:46, 21 May 2016

Read Before You Begin

Before you begin with this worksheet, let's talk about what it will cover.

This worksheet is intended to answer the following questions: How do we evaluate integrals with a computer? When do we evaluate integrals with computers?

Student expectations

You will submit a one-page report that answers each of the questions.

You will need to do some analytical work, and some numerical work. You will need to show your work for both kinds of questions.

If a question asks for a plot or a chart, attach it to your report and refer to it in your answer.

Answer questions with complete sentences.

Problem setup

(Essential information is on handout, but go through it with board/slides/etc)

Numerical integration: background

Equation derivation: referring back to introduction to integrals, rectangle approximations, then through linear and quadratic approximations

Cover each question, cover strategy and writing out before implementing, how to implement in spreadsheet

Spend one day working in computer lab

Worksheet Content

Instructions

The following worksheet will introduce you to numerical integration techniques that can be implemented in a spreadsheet program like Microsoft Excel or Google Sheets.

Read through each section of the worksheet carefully. It contains the information you need to successfully implement Simpson's Rule in a spreadsheet.

You will submit a one-page report that answers each question at the end of the worksheet. Answer each question with complete sentences. This assignment is due in class on (date).

Numerical Integration

Let's start with a review of some numerical integration techniques we learned early on in the course: the left-hand, right-hand, and midpoint rules. These use constants to approximate a function in order to integrate it. We'll then review the Trapezoid Rule and Simpson's Rule, which use lines and quadratics, respectively, to improve the numerical approximation.

In each case, we're interested in approximating the integral of a function,

$ I = \int_{a}^{b} f(x) dx $

We can approximate this integral by splitting up the interval into N sub-intervals, build rectangular strips, and compute their area to approximate the integral. The width of each sub-interval is called the step size is related to the number of sub-intervals N and the limits of integration via the formula:

$ \Delta x = \frac{b-a}{N} $

This partitioning, as applied to a function, is shown in the figure on the right. There are N sub-intervals. The behavior of the function between the points $ f(x_i) $ depends on the numerical integration technique being used.

SimpsonsRule1.jpg

Left Hand, Right Hand, and Midpoint Rules

The left-hand, right-hand, and midpoint rules approximate the behavior of the function as a constant over the interval . Recall that we covered these when we were first introduced to the topic of integration. The constant function has one unknown parameter (y=c), and therefore requires one function evaluation.

SimpsonsRule2.jpg

SimpsonsRule3.jpg

Trapezoid Rule

The Trapezoid Rule uses a line to approximate the behavior of the function (thus turning the “approximating rectangle” into an “approximating trapezoid”). This has two unknowns and requires the function to be evaluated at two points (see Fig. X). The trapezoid rule approximates the area as:

$ A = \Delta x \left( \frac{1}{2} y_0 + y_1 + y_2 + \dots + y_{N-1} + \frac{1}{2} y_{N} \right) $

This formula may also be easier to program as a recurrence relation:

$ A_j = A_{j-1} + \frac{\Delta x}{2} \left( y_{j-1} + y_{j} \right) $

To approximate the total area, simply sum all of the $ A_i $ terms.

SimpsonsRule4.jpg

Simpson's Rule

Simpson's Rule uses a polynomial to approximate the behavior of the function between points and better approximate its integral. The approximating polynomial has three coefficients (three unknowns) and requires three function evaluations. Because Simpson's Rule requires the function at three points (two intervals), it operates two intervals at a time, and therefore Simpson's Rule requires an even number of intervals N.

If we consider the simplest case of Simpson's Rule, with only two intervals, the area under the curve can be approximated using the formula:

$ A = \Delta x \left( \frac{1}{3} y_0 + \frac{4}{3} y_1 + \frac{1}{3} y_2 \right) $

Combining these expressions for a large number of intervals, we can get a general expression for Simpson's Rule:

$ A = \Delta x \left( \frac{1}{3} y_0 + \frac{4}{3} y_1 + \frac{2}{3} y_2 + \frac{4}{3} y_3 + \dots + \frac{4}{3} y_{2k-1} + \frac{2}{3} y_{2k} + \dots + \frac{4}{3} y_{N-3} + \frac{2}{3} y_{N-2} + \frac{4}{3}y_{N-1} + \frac{1}{3} y_{N} \right) $

Similarly, a recurrence relation that's easier to program is:

$ A_{2n} = A_{2(n-1)} + \Delta x \left( \frac{1}{3} y_{2n-2} + \frac{4}{3} y_{2n-1} + \frac{1}{3} y_{2n} \right) $

To approximate the total area, simply sum all of the $ A_i $ terms.

Simpson's Rule fits a polynomial of degree 2 every three data points (two sub-intervals) and approximates the real function with a set of polynomials . Therefore, Simpson's Rule is exact when is a polynomial of degree 2 or less.

SimpsonsRule5.jpg


Worksheet Questions for Calculus 2

On a separate sheet of paper, answer each of the following questions with a complete sentence. Please be considerate of the environment – do not print out your spreadsheets.

Consider the following integral for the questions below:

$ I = \int_{0}^{40} 2 + \cos{( 2 \sqrt{x} )} dx $

Question 1

Create a new worksheet using a spreadsheet program. Use it to approximate the value of the integral I using Simpson's Rule with N = 10 subintervals. Report the absolute error in scientific notation. Report the relative error as a percentage.

Question 2

In a new worksheet, approximate the value of the integral I using Simpson's Rule with N = 50 subintervals. Report the absolute error in scientific notation. Report the relative error as a percentage.

Question 3

In a new worksheet, approximate the value of the integral I using Simpson's Rule with N = 100 subintervals. Report the absolute error in scientific notation. Report the relative error as a percentage.

Question 4

We would expect that the error would be a function of the step size , . Determine what the form of the functional relationship is by plotting vs for the cases above. What is the functional form? Some examples to consider:

$ \epsilon \sim \Delta x $

$ \epsilon \sim \Delta x^n $

$ \epsilon \sim e^{\Delta x} $

$ \epsilon \sim \ln{(\Delta x)} $

Extra Credit

Verify, using the substitution $ u^2 = 4x $, that the indefinite integral is given by:

$ \int 2 + \cos{(2 \sqrt{x})} dx = 2x + \sqrt{x} \sin{(2 \sqrt{x})} - \frac{ \cos{(2 \sqrt{x})} }{ 2 } + C $

References

Flags

Link to all worksheets idea list: Worksheets

Calc II:


Calc III: