##### Related Content

# Simpson's Rule Calculator

*f(x)*=

*a*) =

*b*) =

*n*) =

*n*must be ≤ 200)

*A*= ...

## Simpson's Rule Lesson

#### Lesson Contents

### 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 1

### Simpson's Rule Example Problem 2

## 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.