## Simpson's Rule Calculator

*f(x)*=

*(a)*=

*(b)*=

*(n)*=

(

*n*must be ≤ 200)

Solution

## Simpson's Rule Lesson

### What is Simpson's Rule?

**Simpson's Rule is a method for approximating a definite integral (finding the area under a curve) by matching quadratics to the curve along subintervals and summing all of the subintervals' individual areas.**

Similar to a Riemann Sum, Simpson's Rule is a way to approximate a definite integral. What does this mean exactly? Let's take a look:

For example, let's say that we have a parabola *f(x)* = *x*^{2} as seen below:

Now, if we were interested in finding the area under the curve between *x* = 0 and *x* = 4, we could either perform a definite integral as seen below...

$$\int_{0}^{4} (x^2 ) \text{ }dx$$

...or we can approximate this integral by:

- Choosing a certain number of equal-width subintervals that intersect the graph from
*x*= 0 to*x*= 4. - Calculate the area of each subinterval.
- Add up all of the individual areas within our domain of interest (0 ≤
*x*≤ 4 in this case).

It is important to reiterate that this method yields an *approximation*. This means that there will be an inherent amount of error between the approximated area under the curve, and the actual area under the curve obtained by performing a definite integral. This is due to the fact that the subintervals that intersect the curve do not perfectly fit the contours of the graphed function. This results in parts of each subinterval either going above the curve, or leaving gaps below the curve, resulting in less accurate individual area calculations. Compared to other approximations like Left/Right Riemann Sums and Midpoint Sums, Simpson's Rule yields more accurate approximations.

### Why do we Learn about Simpson's Rule?

When we first learn about integration, we typically begin by learning about Riemann Sums. This allows us to break the area underneath a curve into individual rectangles, calculate the area of each rectangle, then sum all of the individual areas to get an approximation of the definite integral along a specified interval. Simpson's Rule takes this principle further by fitting quadratics (i.e. parabolas) to the curve rather than rectangles. This results in a more accurate approximation.

This is all well and good, but what practical use does Simpson's Rule have? To answer this question, **let's take a look at how submarines maintain stealth by navigating underwater without the use of a Global Positioning System (GPS) or radio signals**.

Submarines utilize an Inertial Navigation System (INS) to navigate without the need to surface for varying amounts of time. An inertial navigation system utilizes an Inertial Measurement Unit (IMU) that consists of, but is not limited to:

- Accelerometers that measure acceleration in the x, y, and z directions.
- Gyroscopes that measure the submarine's rotation about the x, y, and z axes.

By gathering the acceleration versus time data from the accelerometers and integrating (using Simpson's Rule), we can approximate the areas under the acceleration curves in the x, y, and z directions. This tells us the submarine's velocity in each direction. We can then integrate the velocity versus time data to determine the submarine's displacement (position) in each direction.

To account for the change in position with respect to the rotation of the submarine about the x, y, and z axes, we can integrate (using Simpson's Rule) the angular velocity versus time data gathered from the gyroscopes in the inertial measurement unit. This gives us the submarine's angle (attitude) with respect to each axis at a specified time.

After taking the computed positional data from the accelerometers and gyroscopes into account, we can determine where the submarine is without the use of a GPS (Global Positioning System) or radio signals!

### How to Approximate the Area Under a Curve using Simpson's Rule

To approximate a definite integral using Simpson's Rule, utilize the following equations:

$$\begin{align}& \text{1.) }Area = \frac{\Delta x}{3} [f(a) + 4f(a + \Delta x) + 2f(a + 2 \Delta x) + \cdots \\ \\ & \hspace{3ex} \cdots + 2f(a + (n-2) \Delta x) + 4f(a + (n-1) \Delta x) + f(b)] \\ \\ & \hspace{3ex} \text{2.) } \Delta x = \frac{b-a}{n} \end{align}$$

Where Δ*x* is the length of each subinterval, *a* is the left endpoint of the interval, *b* is the right endpoint of the interval, and *n* is the desired number of subintervals to be used for approximation.

This is the recommended order of operations for the above equations:

- Calculate Δ
*x*by plugging in your left endpoint*a*, right endpoint*b*, and number of desired subintervals*n*into equation 2. - Determine where each subinterval starts and ends by indexing your
*x*value beginning with the left endpoint*a*, and then adding*Δx*until you get to the final*x*value for the last segment's endpoint*b*. - Evaluate the function at each applicable
*x*value and sum the results. - Multiply the sum from step 3 with
^{Δx}/_{3}.

### Simpson's Rule Example Problem

$$\begin{align}& \text{1.) Using } \textbf{Simpson's Rule} \text{ with 4 equal subintervals, approximate} \\ \\ & \hspace{3ex} \text{the area under the curve } f(x) \text{ = } x^2+1\text{ from } x \text{ = }1\text{ to } x \text{ = }5\\ \\ & \text{2.) For Simpson's Rule, the approximated area under the curve is:} \\ \\ & \hspace{3ex} A = \frac{\Delta x}{3} \text{ } [f(a) + 4f(a + \Delta x) + 2f(a + 2 \Delta x) \hspace{1ex}+ \hspace{1ex} \cdots \\ \\ & \hspace{3ex} \cdots \hspace{1ex} + 2f(a + (n-2) \Delta x) + 4f(a + (n-1) \Delta x) + f(b)]\\ \\ & \hspace{3ex} \text{Where } \Delta x = \frac{b-a}{n} \text{ is the length of each subinterval, }a \text{ is the left endpoint} \\ & \hspace{3ex} \text{of the interval, } b \text{ is the right endpoint of the interval, and } n \text{ is the desired} \\ & \hspace{3ex} \text{number of subintervals to be used for approximation.}\\ \\ & \text{3.) Calculate } \Delta x \text{ by plugging in given values for } a, b, \text{ and } n \text{:} \\ \\ & \hspace{3ex} \Delta x = \frac{b-a}{n} \hspace{1ex} \Longrightarrow \hspace{1ex} \Delta x = \frac{5 - 1}{4} = 1\\ \\ & \text{4.) Since } \Delta x = 1, \text{our endpoints for our subintervals are:} \\ \\ & \hspace{3ex}x = 1,2,3,4,5\\ \\ & \text{5.) Evaluate function } f(x) = x^2+1\text{ at each of the endpoints found in} \\ & \hspace{3ex} \text{step 4:}\\ \\ & \hspace{3ex} f(1) = {(1)}^2+1 = 2\\ \\ & \hspace{3ex} f(2) = {(2)}^2+1 = 5\\ \\ & \hspace{3ex} f(3) = {(3)}^2+1 = 10\\ \\ & \hspace{3ex} f(4) = {(4)}^2+1 = 17\\ \\ & \hspace{3ex} f(5) = {(5)}^2+1 = 26\\ \\ & \text{6.) Input values found in Step 5 into the equation for Simpson's Rule:}\\ \\ & \hspace{3ex} A = \frac{\Delta x}{3} \text{ } [f(a) + 4f(a + \Delta x) + 2f(a + 2 \Delta x) \hspace{1ex}+ \hspace{1ex} \cdots \\ \\ & \hspace{3ex} \cdots \hspace{1ex} + 2f(a + (n-2) \Delta x) + 4f(a + (n-1) \Delta x) + f(b)]\\ \\ & \hspace{3ex} \Longrightarrow A = \frac{1}{3} [f(1)+4f(2)+2f(3)+4f(4)+f(5)]\\ \\ & \hspace{3ex} \Longrightarrow A = \frac{1}{3} [(2)+4(5)+2(10)+4(17)+(26)]\\ \\ & \hspace{3ex} \Longrightarrow A = \frac{1}{3} [136] = 45.333333333333336\\ \\ & \text{7.) The area } (A) \text{ under the curve } f(x) \text{ using Simpson's Rule} = 45.333333333333336\end{align}$$

## How the Calculator Works

The Simpson's Rule calculator is composed of HTML (Hypertext Markup Language), CSS (Cascading Style Sheets), and JS (JavaScript).

HTML is used to create the framework, or skeleton, of the calculator. This part of the code defines entities such as the solution box and the calculator itself.

CSS is used to style the HTML elements. This is what gives each button of the calculator its specific color and behavioral characteristics such as hover properties that change the button's appearance when you hover over it with your computer mouse.

JavaScript is what gives functionality to the buttons on the calculator and allows the calculator to perform the actual calculations for Simpson's Rule.

When these different languages come together, they deliver an intuitive and detailed experience that helps our users learn about Simpson's Rule more effectively.