# Thoughts on Numerical Integration (Part 10): Trapezoid Rule and exploration of error analysis

Numerical integration is a standard topic in first-semester calculus. From time to time, I have received questions from students on various aspects of this topic, including:

• Why is numerical integration necessary in the first place?
• Where do these formulas come from (especially Simpson’s Rule)?
• How can I do all of these formulas quickly?
• Is there a reason why the Midpoint Rule is better than the Trapezoid Rule?
• Is there a reason why both the Midpoint Rule and the Trapezoid Rule converge quadratically?
• Is there a reason why Simpson’s Rule converges like the fourth power of the number of subintervals?

In this series, I hope to answer these questions. While these are standard questions in a introductory college course in numerical analysis, and full and rigorous proofs can be found on Wikipedia and Mathworld, I will approach these questions from the point of view of a bright student who is currently enrolled in calculus and hasn’t yet taken real analysis or numerical analysis.

In the previous post in this series, I discussed three different ways of numerically approximating the definite integral $\displaystyle \int_a^b f(x) \, dx$, the area under a curve $f(x)$ between $x=a$ and $x=b$.

In this series, we’ll choose equal-sized subintervals of the interval $[a,b]$. If $h = (b-a)/n$ is the width of each subinterval so that $x_k = x_0 + kh$, then the integral may be approximated as

$\int_a^b f(x) \, dx \approx h \left[f(x_0) + f(x_1) + \dots + f(x_{n-1}) \right] \equiv L_n$

using left endpoints,

$\int_a^b f(x) \, dx \approx h \left[f(x_1) + f(x_2) + \dots + f(x_n) \right] \equiv R_n$

using right endpoints, and

$\int_a^b f(x) \, dx \approx h \left[f(c_1) + f(c_2) + \dots + f(c_n) \right] \equiv M_n$

using the midpoints of the subintervals. We have also derived the Trapezoid Rule

$\int_a^b f(x) \, dx \approx \displaystyle \frac{h}{2} [f(x_0) + 2f(x_1) + \dots + 2f(x_{n-1}) + f(x_n)] \equiv T_n$

and Simpson’s Rule (if $n$ is even)

$\int_a^b f(x) \, dx \approx \displaystyle \frac{h}{3} \left[y_0 + 4 y_1 + 2 y_2 + 4 y_3 + \dots + 2y_{n-2} + 4 y_{n-1} + y_{n} \right] \equiv S_n$.

In the previous post in this series, we saw that both the left-endpoint and right-endpoint rules have a linear rate of convergence: if twice as many subintervals are taken, then the error appears to go down by a factor of 2. If ten times as many subintervals are used, then the error should go down by a factor of 10. However, the Midpoint Rule has a quadratic rate of convergence: if twice as many subintervals are taken, then the error appears to go down by a factor of 4. If ten times as many subintervals are used, then the error should go down by a factor of 100.

Let’s now explore the results of the Trapezoid Rule applied to $\displaystyle \int_1^2 x^9 \, dx = 102.3$ using different numbers of subintervals. The results are summarized in the table below.

Once again, the data points fit a quadratic polynomial well, indicating quadratic convergence.

More subtly, it appears that the Trapezoid Rule isn’t quite as good as the Midpoint Rule. Here are the results from the Midpoint Rule (which also appeared in the previous post in this series):

For $n = 100$ subintervals, the error of the Trapezoid Rule is $|102.3191-102.3| = 0.0191$, which the error from the Midpoint Rule is $|102.2904-102.3| = 0.0096$. In other words, while both of these methods are superior to the left- and right-endpoint rules, it appears that the error from the Midpoint Rule is about half of the error from the Trapezoid Rule. The Midpoint Rule appears to be better.

To me, this is far from an obvious conclusion. Geometrically, it’s far from clear that the rectangles from the Midpoint Rule…

… provide a better approximation than using trapezoids …

… yet it appears that’s exactly what happened. This can be rigorously proven, as we’ll explore later in this series.

# Engaging students: Solving exponential equations

In my capstone class for future secondary math teachers, I ask my students to come up with ideas for engaging their students with different topics in the secondary mathematics curriculum. In other words, the point of the assignment was not to devise a full-blown lesson plan on this topic. Instead, I asked my students to think about three different ways of getting their students interested in the topic in the first place.

I plan to share some of the best of these ideas on this blog (after asking my students’ permission, of course).

This student submission comes from my former student Austin Stone. His topic, from Precalculus: solving exponential equations.

What interesting (i.e., uncontrived) word problems using this topic can your students do now?

Exponential equations can be used in lots of different kinds of word problems. One that is pretty common but is very useful for students involves interest rate. “Megan has $20,000 to invest for 5 years and she found an interest rate of 5%. How much money will she have at the end of 5 years if the interest rate compounds monthly?” I would give them the formula A=P(1+r/n)rt. It is pretty easy to convince students that this is a real-world problem and would get the students engaged about exponential equations. You can also reword the problem to ask for how much Megan started with, what the rate is, or how much time the money was in there. That way students get used to solving equations when the variable is in the exponent and when it is not. This also can lead into or us prior knowledge of natural log to solve for the variable in the exponent. How could you as a teacher create an activity or project that involves your topic? Using the basis of the problem I mentioned above, a teacher could create a Project Based Instruction lesson using this idea. The teacher can set up a scenario where, over the course of a week or two, the students would have to decide which bank to make an investment in by calculating how much money they would profit at each bank. The students would have to research different banks and their interest rate. The teacher could also give each group different scenarios where some groups have more money to invest. Students would have to figure out how long they would like to invest. The teacher would give Do It Yourselves and Workshops that deal with solving exponential equations and also getting used to natural log. They would then make a presentation explaining what bank they have chosen and why. They would also have to explain the math that they would have used. How has this topic appeared in the news? To say that exponential equations have been in the news lately would be an understatement. It has virtually been the news this year. COVID-19 is a virus and viruses spread exponentially. This would get students engaged immediately because the topic would be relatable to their own lives. Doctors and scientists try to figure out different ways to “flatten the curve”, which essentially means to make the spread of the virus not exponential anymore. We have all heard people on the news telling the public how to stop the virus from spreading and how not make people around you at risk of contracting it (contributing the exponential spread). We all have most likely seen a doctor or scientist show a graph of the virus’s spread and their predictions on how it will look in the upcoming weeks. This would give students a chance to see that what they are learning can be applied to very crucial things going on in the world around them. References Exponential Functions # Thoughts on Numerical Integration (Part 9): Midpoint rule and exploration of error analysis Numerical integration is a standard topic in first-semester calculus. From time to time, I have received questions from students on various aspects of this topic, including: • Why is numerical integration necessary in the first place? • Where do these formulas come from (especially Simpson’s Rule)? • How can I do all of these formulas quickly? • Is there a reason why the Midpoint Rule is better than the Trapezoid Rule? • Is there a reason why both the Midpoint Rule and the Trapezoid Rule converge quadratically? • Is there a reason why Simpson’s Rule converges like the fourth power of the number of subintervals? In this series, I hope to answer these questions. While these are standard questions in a introductory college course in numerical analysis, and full and rigorous proofs can be found on Wikipedia and Mathworld, I will approach these questions from the point of view of a bright student who is currently enrolled in calculus and hasn’t yet taken real analysis or numerical analysis. In the previous post in this series, I discussed three different ways of numerically approximating the definite integral $\displaystyle \int_a^b f(x) \, dx$, the area under a curve $f(x)$ between $x=a$ and $x=b$. In this series, we’ll choose equal-sized subintervals of the interval $[a,b]$. If $h = (b-a)/n$ is the width of each subinterval so that $x_k = x_0 + kh$, then the integral may be approximated as $\int_a^b f(x) \, dx \approx h \left[f(x_0) + f(x_1) + \dots + f(x_{n-1}) \right] \equiv L_n$ using left endpoints, $\int_a^b f(x) \, dx \approx h \left[f(x_1) + f(x_2) + \dots + f(x_n) \right] \equiv R_n$ using right endpoints, and $\int_a^b f(x) \, dx \approx h \left[f(c_1) + f(c_2) + \dots + f(c_n) \right] \equiv M_n$ using the midpoints of the subintervals. We have also derived the Trapezoid Rule $\int_a^b f(x) \, dx \approx \displaystyle \frac{h}{2} [f(x_0) + 2f(x_1) + \dots + 2f(x_{n-1}) + f(x_n)] \equiv T_n$ and Simpson’s Rule (if $n$ is even) $\int_a^b f(x) \, dx \approx \displaystyle \frac{h}{3} \left[y_0 + 4 y_1 + 2 y_2 + 4 y_3 + \dots + 2y_{n-2} + 4 y_{n-1} + y_{n} \right] \equiv S_n$. In the previous post in this series, we saw that both the left-endpoint and right-endpoint rules have a linear rate of convergence: if twice as many subintervals are taken, then the error appears to go down by a factor of 2. If ten times as many subintervals are used, then the error should go down by a factor of 10. Let’s now explore the results of the midpoint rule applied to $\displaystyle \int_1^2 x^9 \, dx = 102.3$ using different numbers of subintervals. The results are summarized in the table below. The first immediate observation is that these approximations are far better than the left- and right-endpoint rule approximations! Indeed, we see that $M_{10} \approx 101.3$, using only ten subintervals, is a far better approximation than (from the previous post) either $L_{100} = 99.8$ or $R_{100} \approx 104.9$ using 100 subintervals! The lesson to learn: choosing a good algorithm is often far better than simply doing lots of computations. There’s a second observation: the rate of convergence appears to be much, much faster. Indeed, the data points appear to fit a parabola very well instead of a straight line. Said another way, if twice as many subintervals are taken, then the error appears to go down by a factor of 4. If ten times as many subintervals are used, then the error should go down by a factor of 100. This illustrates quadratic convergence, as opposed to the mere linear convergence of the left- and right-endpoint rules. # Engaging students: Compound interest In my capstone class for future secondary math teachers, I ask my students to come up with ideas for engaging their students with different topics in the secondary mathematics curriculum. In other words, the point of the assignment was not to devise a full-blown lesson plan on this topic. Instead, I asked my students to think about three different ways of getting their students interested in the topic in the first place. I plan to share some of the best of these ideas on this blog (after asking my students’ permission, of course). This student submission comes from my former student Mason Maynard. His topic, from Precalculus: compound interest. What interesting (i.e., uncontrived) word problems using this topic can your students do now? (You may find resources such as http://www.spacemath.nasa.gov to be very helpful in this regard; feel free to suggest others.) • A deposit of$3000 earns 2% interest compounded semiannually. How much money is in the bank after for 4 years?
• A deposit of $2150 earns 6% interest compounded quarterly. How much money is in the bank after for 6 years? • A deposit of$495 earns 3% interest compounded annually. How much money is in the bank after for 3 years?

These word problems are some of the basic compound interest problems that your students learn how to do where you just plug in the correct values for their corresponding variables.

• If you invested $1,000 in an account paying an annual percentage rate (quoted rate) compounded daily (based on a bank year of 360 days) and you wanted to have$2,500 in your account at the end of your investment time, what interest rate would you need if the investment time were 1 year, 10 years, 20 years, 100 years?
• If you invested $500 in an account paying an annual percentage rate compounded quarterly , and you wanted to have$2,500 in your account at the end of your investment time, what interest rate would you need if the investment time were 1 year, 10 years, 20 years, 100 years?

These are the types of problems that get more difficult for the students. You want them to use compound interest to solve but then they must incorporate logs into their solutions because they are looking for time instead of interest.

How does this topic extend what your students should have learned in previous courses?

With compound interest, students first learn about the simple interest formula. The only main difference is that you start to include exponents with compound interests. Then when you introduce your students to compound interest, you start to get into some more complicated problems. After they learn about compound interest and its basic problems, then you transition into logs with your students. This is used in compound interest and instead of just looking for the interest that will be accumulated after a specific amount of time, you then shift the variable around that you are looking for. The most coming type of problem that refers to this is they give you all of the information except for the amount time it takes to get a certain amount of interest. The last thing that leads up to compound interest in Calculus is when you transition from calculating the amount of interested over specific time intervals and a specific amount of times you compound it to calculating it with compounding it continuously over a specific time interval.

How have different cultures throughout time used this topic in their society?

Interest is something you have to pay on a load. Depending on what side you are and how thinks go, you are either getting some more money back that what you invested or you are paying off a massive debt. Some think that the idea behind charging loans on interest came from the early days of neighbors loaning there cattle to one another. What is really unique about this is that the words in the Egyptian, ancient Greek and Sumerian languages is connected to cattle and their offspring. This leads some to believe that interest came about due to the natural increase of the herd that occurred when you loaned out your cattle.

The first evidence that comes of a compound interest problem dates back to 2000-1700 B.C. in Babylon. A clay tablet was found and the unique thing is that the interest rate use to solve it was not written. Some researchers assume that the rate was 20% due to that mainly all the other compound interest problems dating back closer to this used it. What is really crazy is that 20% worked to solve the problem. The only thing that was wrong was that the time was corresponding to the Babylon calendar of 360 days instead of our 365 days.

In 50 B.C. Cicero writes to a friend in Rome. The letter tells that he would not normally recognize more than 12 percent interest on a loan, even though a decree was passed which required money lenders to charge no more than 12 percent. Cicero would then write a few days later that they will pay back the loan in 6 years will 12 percent interest and more money will be added each year.

Resources:

Compound Interest History:

https://www.cambridge.org/core/services/aop-cambridge-core/content/view/799CB1D40CDD46F3010767BFC60F24DB/S1357321719000254a.pdf/emergence_of_compound_interest.pdf

Word Problems:

https://www.basic-mathematics.com/compound-interest-word-problems.html

http://www.sosmath.com/algebra/logs/log5/log51/log51.html

# Thoughts on Numerical Integration (Part 8): Left and right endpoint rules and exploration of error analysis

Numerical integration is a standard topic in first-semester calculus. From time to time, I have received questions from students on various aspects of this topic, including:

• Why is numerical integration necessary in the first place?
• Where do these formulas come from (especially Simpson’s Rule)?
• How can I do all of these formulas quickly?
• Is there a reason why the Midpoint Rule is better than the Trapezoid Rule?
• Is there a reason why both the Midpoint Rule and the Trapezoid Rule converge quadratically?
• Is there a reason why Simpson’s Rule converges like the fourth power of the number of subintervals?

In this series, I hope to answer these questions. While these are standard questions in a introductory college course in numerical analysis, and full and rigorous proofs can be found on Wikipedia and Mathworld, I will approach these questions from the point of view of a bright student who is currently enrolled in calculus and hasn’t yet taken real analysis or numerical analysis.

In the previous post in this series, I discussed three different ways of numerically approximating the definite integral $\displaystyle \int_a^b f(x) \, dx$, the area under a curve $f(x)$ between $x=a$ and $x=b$.

In this series, we’ll choose equal-sized subintervals of the interval $[a,b]$. If $h = (b-a)/n$ is the width of each subinterval so that $x_k = x_0 + kh$, then the integral may be approximated as

$\int_a^b f(x) \, dx \approx h \left[f(x_0) + f(x_1) + \dots + f(x_{n-1}) \right] \equiv L_n$

using left endpoints,

$\int_a^b f(x) \, dx \approx h \left[f(x_1) + f(x_2) + \dots + f(x_n) \right] \equiv R_n$

using right endpoints, and

$\int_a^b f(x) \, dx \approx h \left[f(c_1) + f(c_2) + \dots + f(c_n) \right] \equiv M_n$

using the midpoints of the subintervals. We have also derived the Trapezoid Rule

$\int_a^b f(x) \, dx \approx \displaystyle \frac{h}{2} [f(x_0) + 2f(x_1) + \dots + 2f(x_{n-1}) + f(x_n)] \equiv T_n$

and Simpson’s Rule (if $n$ is even)

$\int_a^b f(x) \, dx \approx \displaystyle \frac{h}{3} \left[y_0 + 4 y_1 + 2 y_2 + 4 y_3 + \dots + 2y_{n-2} + 4 y_{n-1} + y_{n} \right] \equiv S_n$.

All of the above approximations to $\displaystyle \int_a^b f(x) \, dx$ are precisely that — approximations. That begs the obvious question: how can we get better approximations. One obvious answer is taking more subintervals. The figures below show the left-endpoint approximations using $n = 4$ and $n = 40$ subintervals. Geometrically, it’s clear that the orange rectangles in the second picture do a better job of approximating the area under the curve. Unfortunately, simply taking more subintervals has its limitations. Using a spreadsheet as in the previous post in this series, one can implement 100 or even 1000 subintervals without much difficult. However, as demonstrated in the video below, implementing any of these methods with 10,000 subintervals is pretty time-consuming. (Tl/dw: It can take literally a couple of minutes.)

Instead of relying on sheer computational firepower, let’s instead investigate how good these numerical methods actually are. To begin, let’s explore the left-endpoint rule applied to $\displaystyle \int_1^2 x^9 \, dx = 102.3$ using different numbers of subintervals. The results are summarized in the table below. As $n$ increases, the left endpoint approximations $L_n$ are indeed getting closer and closer to the actual value of $\displaystyle \int_1^2 x^9 \, dx = 102.3$. Interestingly, when the width $h$ is plotted with these approximations, the data points fall almost exactly on a straight line. The same phenomenon occurs when using right endpoints: So, it appears that the errors in both the left- and right-endpoint rules are a linear function of the size of the subintervals. Said another way, if twice as many subintervals are taken, then the error appears to go down by a factor of 2. If ten times as many subintervals are used, then the error should go down by a factor of 10. As we’ll see in the next few posts, the errors for the Midpoint Rule, the Trapezoid Rule, and especially Simpson’s Rule are much better than the errors from these two methods.

# Engaging students: Infinite geometric series

In my capstone class for future secondary math teachers, I ask my students to come up with ideas for engaging their students with different topics in the secondary mathematics curriculum. In other words, the point of the assignment was not to devise a full-blown lesson plan on this topic. Instead, I asked my students to think about three different ways of getting their students interested in the topic in the first place.

I plan to share some of the best of these ideas on this blog (after asking my students’ permission, of course).

This student submission comes from my former student Brendan Gunnoe. His topic, from Precalculus: infinite geometric series.

Curriculum:

Students can use the formula for an infinite geometric series to discover the formula for a finite geometric series. The teacher would start by posing the question “Can we use the infinite geometric series to come up with a formula for the finite version?” and writing out a series like so

$\displaystyle \sum_{i=0}^\infty ar^i = ar^0 + ar^1 + ar^2 + \dots + ar^{n-1} + ar^n + ar^{n+1} + \dots$

Next, the instructor could ask questions like “If we’re looking for the sum up to the nth term, where do we need to chop off the terms to get what we want?,” “Does the ending part look familiar?”, and “How can we rewrite the chopped off part so that it looks like what we already know?”. The teacher guides the students into manipulating the formula to get this result

$\displaystyle \sum_{i=0}^\infty ar^i = ar^0 + ar^1 + ar^2 + \dots + ar^{n-1} + ar^n + ar^{n+1} + \dots$

$\displaystyle \sum_{i=0}^\infty ar^i = ar^0 + ar^1 + ar^2 + \dots + ar^{n-1} + ar^n + \sum_{j=n+1}^\infty ar^j$

$ar^0 + ar^1 + ar^2 + \dots + ar^{n-1} + ar^n = \displaystyle \sum_{i=0}^\infty ar^i - \sum_{j=n+1}^\infty ar^j$

The teacher notes that the last sum can be simplified to make it easier to see by doing a substitution of $k = j -n-1$. Adjusting the bounds and substituting in the new index, we get

$ar^0 + ar^1 + ar^2 + \dots + ar^{n-1} + ar^n = \displaystyle \sum_{i=0}^\infty ar^i - \sum_{k=0}^\infty ar^{n+1+k}$

$= \displaystyle \sum_{i=0}^\infty ar^i - \sum_{k=0}^\infty ar^{n+1}r^k$

$= \displaystyle \sum_{i=0}^\infty ar^i - r^{n+1} \sum_{k=0}^\infty ar^k$

Note that the two sums are identical, besides the index name, so we can factor and get

$ar^0 + ar^1 + ar^2 + \dots + ar^{n-1} + ar^n = a(1-r^{n+1}) \displaystyle \sum_{i=0}^\infty r^i$

Lastly, we utilize our formula for an infinite geometric series and get

$ar^0 + ar^1 + ar^2 + \dots + ar^{n-1} + ar^n = a(1-r^{n+1}) \displaystyle \frac{1}{1-r}$

$ar^0 + ar^1 + ar^2 + \dots + ar^{n-1} + ar^n = \displaystyle a\frac{1-r^{n+1}}{1-r}$

$ar^0 + ar^1 + ar^2 + \dots + ar^{n-1} + ar^n = \displaystyle a\frac{r^{n+1}-1}{r-1}$

Although the infinite series requires $|r|<1$ , the finite version works for all real $r$. Although the formal proof that this is the correct formula might be beyond the scope of the intended class, it can easily be done with induction.

Technology:

https://www.khanacademy.org/math/geometry-home/geometry-volume-surface-area/koch-snowflake/v/area-of-koch-snowflake-part-1-advanced

Sal Khan, one of recent history’s most well-known STEM educators, has a fantastic video that shows the relationship between a fractal known as the Koch snowflake and the geometric series. Khan works through the derivation of the formulas for the perimeter and area of an the nth­ iteration of the Koch snowflake. It turns out that both the area and perimeters for each iteration can be expressed using a geometric series, but the perimeter diverges to infinity while the area converges. Such a result makes sense intuitively since you can fit every iteration inside of a finite box that is slightly larger than the snowflake, and thus bounding the area, yet it would require an infinitely long wire to go around the perimeter of the limiting shape. Since fractals are not normally included in the math curriculum, showing how math can be used in interesting and different ways to solve problem can be very engaging for students.

Culture:

There is a strong connection between geometric series, fractals, and self-similarity, all with a relatively simple nature. Fractals have been used in architecture and art for a very long time. Examples of self-similarity seen in ancient cultures include Hindu temples, with their structure being composed of self-similar units, and Islamic geometric art found in the domes of mosques.

Since the invention of the computer in the mid-20th century, more detailed and intricate digital art has been made popular. Although not exactly a geometric series, the Mandelbrot set acts very much like a fractal and was among the first of the uses of a computer to investigate the properties of fractals. It has been used in many ways to make animations, photos and other digital arts.

Another link between fractals and art can be found in the Legend of Zelda games. One of the iconic symbols of the game is called the triforce, which is an equilateral triangle that’s been cut into 4 smaller triangles with the middle piece removed. Such a shape is the first iteration of a fractal known as the Sierpinski triangle. As you can see, fractals can be found in all kinds of art, coming in many different forms.

https://en.wikipedia.org/wiki/Fractal_art