Worksheets/Simpsons Rule: Difference between revisions
From charlesreid1
| Line 95: | Line 95: | ||
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. | 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. | ||
=Questions= | =Calc II Questions= | ||
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. | 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. | ||
| Line 144: | Line 144: | ||
\epsilon \sim \ln{(\Delta x)} | \epsilon \sim \ln{(\Delta x)} | ||
</math> | </math> | ||
=References= | |||
=Flags= | |||
{{Worksheets}} | |||
Revision as of 10:43, 8 May 2016
Background
When might we need to evaluate an integral with data?
Numerical routine to integrate two functions and find a centroid - Magrab p. 154 (uses quadc() routine)
Expectations:
- Answers with complete sentences
- Some analytical work, some numerical work
- Final answers in report!
- Plot/chart to answer question
PowerPoint Problem Setup
Explanation of numerical integration background, equation derivation
Cover the questions
Cover strategy, writing out what to do before implementing, how to implement in a spreadsheet
Spend a day working in a 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.
Answer each question at the end of the worksheet with a complete sentence on a separate sheet of paper. This assignment is due in class on XYZ.
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.
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.
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.
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.
Calc II Questions
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
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 $
Question 2
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 3
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 4
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 5
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 e^{\Delta x} $
$ \epsilon \sim \Delta x^n $
$ \epsilon \sim \ln{(\Delta x)} $