## Section5.9Numerical Integration

###### Motivating Questions
• How do we accurately evaluate a definite integral such as $\int_0^1 e^{-x^2} \, dx$ when we cannot use the First Fundamental Theorem of Calculus because the integrand lacks an elementary algebraic antiderivative? Are there ways to generate accurate estimates without using extremely large values of $n$ in Riemann sums?

• What is the Trapezoid Rule, and how is it related to left, right, and middle Riemann sums?

• How are the errors in the Trapezoid Rule and Midpoint Rule related, and how can they be used to develop an even more accurate rule?

When we first explored finding the net signed area bounded by a curve, we developed the concept of a Riemann sum4.2 as a helpful estimation tool and a key step in the definition of the definite integral. Recall that the left, right, and middle Riemann sums of a function $f$ on an interval $[a,b]$ are given by

\begin{align} L_n = f(x_0) \Delta x + f(x_1) \Delta x + \cdots + f(x_{n-1}) \Delta x \amp= \sum_{i = 0}^{n-1} f(x_i) \Delta x,\label{E-Left}\tag{5.15}\\ R_n = f(x_1) \Delta x + f(x_2) \Delta x + \cdots + f(x_{n}) \Delta x \amp= \sum_{i = 1}^{n} f(x_i) \Delta x,\label{E-Right}\tag{5.16}\\ M_n = f(\overline{x}_1) \Delta x + f(\overline{x}_2) \Delta x + \cdots + f(\overline{x}_{n}) \Delta x \amp= \sum_{i = 1}^{n} f(\overline{x}_i) \Delta x\text{,}\label{E-Mid}\tag{5.17} \end{align}

where $x_0 = a\text{,}$ $x_i = a + i\Delta x\text{,}$ $x_n = b\text{,}$ and $\Delta x = \frac{b-a}{n}\text{.}$ For the middle sum, we defined $\overline{x}_{i} = (x_{i-1} + x_i)/2\text{.}$

A Riemann sum is a sum of (possibly signed) areas of rectangles. The value of $n$ determines the number of rectangles, and our choice of left endpoints, right endpoints, or midpoints determines the heights of the rectangles. We can see the similarities and differences among these three options in Figure5.77, where we consider the function $f(x) = \frac{1}{20}(x-4)^3 + 7$ on the interval $[1,8]\text{,}$ and use 5 rectangles for each of the Riemann sums.

Part (d) of Example4.36 explored how to determine if $L_n$ and $R_n$ are underestimates or overestimates of $\int_a^b f(x) \, dx$ when $f(x)$ is increasing. Similar statements can be made when $f(x)$ is decreasing. These are summarized next.

###### Error types when approximating area using left and right Riemann sums
• If $f(x)$ is increasing on $[a,b] \text{,}$ then $L_n$ underestimates $\int_a^b f(x) \, dx$ and $R_n$ overestimates $\int_a^b f(x) \, dx\text{.}$

• If $f(x)$ is decreasing on $[a,b] \text{,}$ then $L_n$ overestimates $\int_a^b f(x) \, dx$ and $R_n$ underestimates $\int_a^b f(x) \, dx\text{.}$

While it is a good exercise to compute a few Riemann sums by hand, just to ensure that we understand how they work and how varying the function, the number of subintervals, and the choice of endpoints or midpoints affects the result, using computing technology is a quick way to determine $L_n\text{,}$ $R_n\text{,}$ and $M_n\text{.}$ Any computer algebra system will offer this capability.

In this section we explore several different alternatives for estimating definite integrals. Our main goal is to develop formulas to estimate definite integrals accurately without using a large numbers of rectangles.

###### Example5.78

As we begin to investigate ways to approximate definite integrals, it will be insightful to compare results to integrals whose exact values we know. To that end, the following sequence of questions centers on $\int_0^3 x^3 \, dx\text{.}$

1. Use the applet at http://gvsu.edu/s/a9 with the function $f(x) = x^3$ on the window of $x$ values from $0$ to $3$ to compute $L_3\text{,}$ the left Riemann sum with three subintervals.

$L_3=9$

Solution

In addition to changing $f(x)$ to $f(x)=x^3$ and the number of subintervals to $3 \text{,}$ make sure to change the Sample Point Placement so that "Relative" is checked and the slide bar is all the way to the left. You'll see that now it is sampling $f(x)$ values from the left side of each sub-interval.

\begin{equation*} L_3=9 \end{equation*}
2. Likewise, use the applet to compute $R_3$ and $M_3\text{,}$ the right and middle Riemann sums with three subintervals, respectively.

$M_3=19.125 \ , R_3=36$

Solution

First change $f(x)$ and the number of subintervals to $f(x)=x^3$ and $n=3\text{.}$ For $R_3\text{,}$ make sure to change the Sample Point Placement so that "Relative" is checked and the slide bar is all the way to the right. You'll see that now it is sampling $f(x)$ values from the right side of each subinterval. For $M_3\text{,}$ make sure to change the Sample Point Placement so that "Relative" is checked and the slide bar is in the middle and the "midpoint" label shows. You'll see that now it is sampling $f(x)$ values from the middle of each interval.

\begin{equation*} M_3=19.125 \ , R_3=36 \end{equation*}
3. Use the Fundamental Theorem of Calculus to compute the exact value of $I = \int_0^3 x^3 \, dx\text{.}$

Solution
\begin{align*} I&=\int_0^3 x^3 \, dx \\ &= \left.\frac{1}{4}x^4 \right|_{0}^{3} \\ &=\frac{3^4}{4}-\frac{0^4}{4}\\ &=20.25 \end{align*}
4. We define the error in an approximation of a definite integral to be the difference between the integral's exact value and the approximation's value. What is the error that results from using $L_3\text{?}$ From $R_3\text{?}$ From $M_3\text{?}$

\begin{equation*} E_{L,3}= 11.25 \end{equation*}
\begin{equation*} E_{R,3}=-15.75 \end{equation*}
\begin{equation*} E_{M,3}=1.125 \end{equation*}
Solution

Denote the error from each approximation $E_{L,3}, E_{R,3}, \text{ and } E_{M,3}\text{.}$ Then

\begin{equation*} E_{L,3}=I-L_3=20.25-9 =11.25 \end{equation*}
\begin{equation*} E_{R,3}=I-R_3=20.25-36=-15.75 \end{equation*}
\begin{equation*} E_{M,3}=I-M_3=20.25-19.125=1.125 \end{equation*}
5. In what follows in this section, we will learn a new approach to estimating the value of a definite integral known as the Trapezoid Rule. The basic idea is to use trapezoids, rather than rectangles, to estimate the area under a curve. What is the formula for the area of a trapezoid with bases of length $b_1$ and $b_2$ and height $h\text{?}$

Solution

The area of a trapezoid with bases of length $b_1$ and $b_2$ and height $h$ is

\begin{equation*} A=\frac{h(b_1+b_2)}{2}\text{.} \end{equation*}
6. Working by hand, estimate the area under $f(x) = x^3$ on $[0,3]$ using three subintervals and three corresponding trapezoids. What is the error in this approximation? How does it compare to the errors you calculated in (d)?

\begin{equation*} T_3=\frac{45}{2}=22.5 \end{equation*}
\begin{equation*} E_{T,3}=-2.25 \end{equation*}
Solution

The left-most trapezoid has base lengths 0 and 1 and height 1, so the area of the first trapezoid is $\frac{1}{2} (0+1)\cdot 1=\frac{1}{2}\text{.}$ The middle trapezoid has base lengths 1 and 8 and height 1, so the area of the second trapezoid is $\frac{1}{2}(1+8) \cdot 1=\frac{9}{2} \text{.}$ The right-most trapezoid has base lengths 8 and 27 and height 1, so the area of the third trapezoid is $\frac{1}{2}(8+27)\cdot 1=\frac{35}{2}\text{.}$ Therefore, the approximate area under the graph of $f(x)=x^3$ from $0$ to $3$ using the trapezoid rule with 3 subintervals is $T_3= \frac{1}{2} + \frac{9}{2} + \frac{35}{2}=\frac{45}{2}=22.5\text{.}$

The error is $E_{T,3}=20.25-22.5=-2.25 \text{.}$ Using trapezoids creates a smaller error compared to $L_3$ and $R_3 \text{.}$ The magnitude of the error from approximating using $M_3$ is half the magnitude of the error from approximating using $T_3 \text{,}$ but they have opposite signs.

### SubsectionThe Trapezoid Rule

So far, we have used the simplest possible quadrilaterals (that is, rectangles) to estimate areas. It is natural, however, to wonder if other familiar shapes might serve us even better.

An alternative to $L_n\text{,}$ $R_n\text{,}$ and $M_n$ is called the Trapezoid Rule. Rather than using a rectangle to estimate the (signed) area bounded by $y = f(x)$ on a small interval, we use a trapezoid. For example, in Figure5.80, we estimate the area under the curve using three subintervals and the trapezoids that result from connecting the corresponding points on the curve with straight lines.

The biggest difference between the Trapezoid Rule and a Riemann sum is that on each subinterval, the Trapezoid Rule uses two function values, rather than one, to estimate the (signed) area bounded by the curve. For instance, to compute $D_1\text{,}$ the area of the trapezoid on $[x_0, x_1]\text{,}$ we observe that the left base has length $f(x_0)\text{,}$ while the right base has length $f(x_1)\text{.}$ The height of the trapezoid is $x_1 - x_0 = \Delta x = \frac{b-a}{3}\text{.}$ The area of a trapezoid is the average of the bases times the height, so we have

\begin{equation*} D_1 = \frac{1}{2}(f(x_0) + f(x_1)) \cdot \Delta x\text{.} \end{equation*}

Using similar computations for $D_2$ and $D_3\text{,}$ we find that $T_3\text{,}$ the trapezoidal approximation to $\int_a^b f(x) \, dx$ is given by

\begin{align*} T_3 &= D_1 + D_2 + D_3\\ &= \frac{1}{2}(f(x_0) + f(x_1)) \cdot \Delta x + \frac{1}{2}(f(x_1) + f(x_2)) \cdot \Delta x + \frac{1}{2}(f(x_2) + f(x_3)) \cdot \Delta x\text{.} \end{align*}

Because both left and right endpoints are being used, we recognize within the trapezoidal approximation the use of both left and right Riemann sums. Rearranging the expression for $T_3$ by removing factors of $\frac{1}{2}$ and $\Delta x \text{,}$ grouping the left endpoint and right endpoint evaluations of $f\text{,}$ we see that

$$T_3 = \frac{1}{2} \left[ f(x_0) + f(x_1) + f(x_2) \right] \Delta x + \frac{1}{2} \left[ f(x_1) + f(x_2) + f(x_3) \right] \Delta x\text{.}\label{E-Trap3}\tag{5.18}$$

We now observe that two familiar sums have arisen. The left Riemann sum $L_3$ is $L_3 = f(x_0) \Delta x + f(x_1) \Delta x + f(x_2) \Delta x\text{,}$ and the right Riemann sum is $R_3 = f(x_1) \Delta x + f(x_2) \Delta x + f(x_3) \Delta x\text{.}$ Substituting $L_3$ and $R_3$ for the corresponding expressions in Equation(5.18), it follows that $T_3 = \frac{1}{2} \left[ L_3 + R_3 \right]\text{.}$ We have thus seen a very important result: using trapezoids to estimate the (signed) area bounded by a curve is the same as averaging the estimates generated by using left and right endpoints.

###### The Trapezoid Rule

The trapezoidal approximation, $T_n\text{,}$ of the definite integral $\int_a^b f(x) \, dx$ using $n$ subintervals is given by the rule

\begin{align*} T_n =\mathstrut \amp \left[\frac{1}{2}(f(x_0) + f(x_1)) + \frac{1}{2}(f(x_1) + f(x_2)) + \cdots + \frac{1}{2}(f(x_{n-1}) + f(x_n)) \right] \Delta x.\\ =\mathstrut \amp \sum_{i=0}^{n-1} \frac{1}{2}(f(x_i) + f(x_{i+1})) \Delta x\text{.} \end{align*}

Moreover, $T_n = \frac{1}{2} \left[ L_n + R_n \right]\text{.}$

###### Example5.81

In this example, we explore the relationships among the errors generated by left, right, midpoint, and trapezoid approximations to the definite integral $\int_1^2 \frac{1}{x^2} \, dx$

1. Use the First FTC to evaluate $\int_1^2 \frac{1}{x^2} \, dx$ exactly.

2. Use appropriate computing technology to compute the following approximations for $\int_1^2 \frac{1}{x^2} \, dx\text{:}$ $T_4\text{,}$ $M_4\text{,}$ $T_8\text{,}$ and $M_8\text{.}$

3. Recall that the error of an approximation is the difference between the exact value of the definite integral and the resulting approximation. For instance, if we let $E_{T,4}$ represent the error that results from using the trapezoid rule with 4 subintervals to estimate the integral, we have

\begin{equation*} E_{T,4} = \int_1^2 \frac{1}{x^2} \, dx - T_4\text{.} \end{equation*}

Similarly, we compute the error of the midpoint rule approximation with 8 subintervals by the formula

\begin{equation*} E_{M,8} = \int_1^2 \frac{1}{x^2} \, dx - M_8\text{.} \end{equation*}

Based on your work in (a) and (b) above, compute $E_{T,4}\text{,}$ $E_{T,8}\text{,}$ $E_{M,4}\text{,}$ $E_{M,8}\text{.}$

4. Which rule consistently over-estimates the exact value of the definite integral? Which rule consistently under-estimates the definite integral?

5. What behavior(s) of the function $f(x) = \frac{1}{x^2}$ lead to your observations in (d)?

Hint
1. $\frac{1}{x^2} = x^{-2}\text{.}$

2. Use a computational device.

3. Use a computational device.

4. Which estimate is larger than the true value of the definite integral?

5. Note that how the curve bends makes a big difference in whether the trapezoid rule over- or under-estimates the value of the definite integral.

1. $\int_1^2 \dfrac{1}{x^2} dx = \dfrac{1}{2}\text{.}$

2. The table below gives values of the trapezoid rule and corresponding errors for different $n$-values.

 $n$ $T_n$ $E_{T,n}$ $4$ $0.50899$ $-0.50899$ $8$ $0.50227$ $-0.50227$ $16$ $0.50057$ $-0.50057$
3. The table below gives values of the midpoint rule and corresponding errors for different $n$-values.

 $n$ $M_n$ $E_{M,n}$ $4$ $0.49555$ $0.00445$ $8$ $0.49887$ $0.00113$ $16$ $0.49972$ $0.00028$
4. The trapezoid rule overestimates; the midpoint rule underestimates.

5. $f(x) = \dfrac{1}{x^2}$ is concave up on $[1, 2]\text{.}$

Solution
1. $\int_1^2 \dfrac{1}{x^2} dx = \left. -x^{-1} \right|_1^2 = -\dfrac{1}{2} + 1 = \dfrac{1}{2}\text{.}$

2. The table below gives values of the trapezoid rule and corresponding errors for different $n$-values.

 $n$ $T_n$ $E_{T,n}$ $4$ $0.50899$ $-0.50899$ $8$ $0.50227$ $-0.50227$ $16$ $0.50057$ $-0.50057$
3. The table below gives values of the midpoint rule and corresponding errors for different $n$-values.

 $n$ $M_n$ $E_{M,n}$ $4$ $0.49555$ $0.00445$ $8$ $0.49887$ $0.00113$ $16$ $0.49972$ $0.00028$
4. From the errors in comparison to the known exact value, we see that the trapezoid rule overestimates this definite integral and the midpoint rule underestimates this definite integral.

5. The graph of the function given by $f(x) = \dfrac{1}{x^2}$ is concave up on the interval $[1, 2]\text{.}$ Because of this fact, we can see graphically that the line forming the top of each trapezoid lies fully above the curve, and thus the trapezoid rule overestimates the true value of the definite integral. Later in this section we'll see graphically why this concavity makes the midpoint rule an underestimate.

### SubsectionComparing the Midpoint and Trapezoid Rules

We know from the definition of the definite integral that if we let $n$ be large enough, we can make any of the approximations $L_n\text{,}$ $R_n\text{,}$ and $M_n$ as close as we'd like (in theory) to the exact value of $\int_a^b f(x) \, dx\text{.}$ Thus, it may be natural to wonder why we ever use any rule other than $L_n$ or $R_n$ (with a sufficiently large $n$ value) to estimate a definite integral. One of the primary reasons is that as $n \to \infty\text{,}$ $\Delta x = \frac{b-a}{n} \to 0\text{,}$ and thus in a Riemann sum calculation with a large $n$ value, we end up multiplying by a number that is very close to zero. Doing so often generates roundoff error, because representing numbers close to zero accurately is a persistent challenge for computers.

Hence, we explore ways to estimate definite integrals to high levels of precision, but without using extremely large values of $n\text{.}$ Paying close attention to patterns in errors, such as those observed in Example5.81, is one way to begin to see some alternate approaches.

To begin, we compare the errors in the Midpoint and Trapezoid rules. First, consider a function that is concave up on a given interval, and picture approximating the area bounded on that interval by both the Midpoint and Trapezoid rules using a single subinterval.

As seen in Figure5.82, it is evident that whenever the function is concave up on an interval, the Trapezoid Rule with one subinterval, $T_1\text{,}$ will overestimate the exact value of the definite integral on that interval. From a careful analysis of the line that bounds the top of the rectangle for the Midpoint Rule (shown in magenta), we see that if we rotate this line segment until it is tangent to the curve at the midpoint of the interval (as shown at right in Figure5.82), the resulting trapezoid has the same area as $M_1\text{,}$ and this value is less than the exact value of the definite integral. Thus, when the function is concave up on the interval, $M_1$ underestimates the integral's true value.

The preceding discussion explores how to determine if $M_n$ and $T_n$ are underestimates or overestimates of $\int_a^b f(x) \, dx$ if $f(x)$ is concave up. Similar statements can be made when $f(x)$ is concave down. These are summarized next.

###### Error types when approximating using Midpoint and Trapezoid Rules
• If $f(x)$ is concave up on $[a,b] \text{,}$ then $M_n$ underestimates $\int_a^b f(x) \, dx$ and $T_n$ overestimates $\int_a^b f(x) \, dx\text{.}$

• If $f(x)$ is concave down on $[a,b] \text{,}$ then $M_n$ overestimates $\int_a^b f(x) \, dx$ and $T_n$ underestimates $\int_a^b f(x) \, dx\text{.}$

Next, we compare the size of the errors between $M_n$ and $T_n\text{.}$ Again, we focus on $M_1$ and $T_1$ on an interval where the concavity of $f$ is consistent. In Figure5.83, where the error of the Trapezoid Rule is shaded in red, while the error of the Midpoint Rule is shaded lighter red, it is visually apparent that the error in the Trapezoid Rule is more significant. To see how much more significant, let's consider two examples and some particular computations.

If we let $f(x) = 1-x^2$ and consider $\int_0^1 f(x) \,dx\text{,}$ we know by the First FTC that the exact value of the integral is

\begin{equation*} \int_0^1 (1-x^2) \, dx = x - \frac{x^3}{3} \bigg\vert_0^1 = \frac{2}{3}\text{.} \end{equation*}

Using appropriate technology to compute $M_4\text{,}$ $M_8\text{,}$ $T_4\text{,}$ and $T_8\text{,}$ as well as the corresponding errors $E_{M,4}\text{,}$ $E_{M,8}\text{,}$ $E_{T,4}\text{,}$ and $E_{T,8}\text{,}$ as we did in Example5.81, we find the results summarized in Table5.84. We also include the approximations and their errors for the example $\int_1^2 \frac{1}{x^2} \, dx$ from Example5.81.

For a given function $f$ and interval $[a,b]\text{,}$ $E_{T,4} = \int_a^b f(x) \,dx - T_4$ calculates the difference between the exact value of the definite integral and the approximation generated by the Trapezoid Rule with $n = 4\text{.}$ If we look at not only $E_{T,4}\text{,}$ but also the other errors generated by using $T_n$ and $M_n$ with $n = 4$ and $n = 8$ in the two examples noted in Table5.84, we see an evident pattern. Not only is the sign of the error (which measures whether the rule generates an over- or under-estimate) tied to the rule used and the function's concavity, but the magnitude of the errors generated by $T_n$ and $M_n$ seems closely connected. In particular, the errors generated by the Midpoint Rule seem to be about half the size of those generated by the Trapezoid Rule.

That is, we can observe in both examples that $E_{M,4} \approx -\frac{1}{2} E_{T,4}$ and $E_{M,8} \approx -\frac{1}{2}E_{T,8}\text{.}$ This property of the Midpoint and Trapezoid Rules turns out to hold in general: for a function of consistent concavity, the error in the Midpoint Rule has the opposite sign and approximately half the magnitude of the error of the Trapezoid Rule. Written symbolically,

\begin{equation*} E_{M,n} \approx -\frac{1}{2} E_{T,n}\text{.} \end{equation*}

This important relationship suggests a way to combine the Midpoint and Trapezoid Rules to create an even more accurate approximation to a definite integral.

### SubsectionSimpson's Rule

When we first developed the Trapezoid Rule, we observed that it is an average of the Left and Right Riemann sums:

\begin{equation*} T_n = \frac{1}{2}(L_n + R_n)\text{.} \end{equation*}

If a function is always increasing or always decreasing on the interval $[a,b]\text{,}$ one of $L_n$ and $R_n$ will over-estimate the true value of $\int_a^b f(x) \, dx\text{,}$ while the other will under-estimate the integral. Thus, the errors found in $L_n$ and $R_n$ will have opposite signs; so averaging $L_n$ and $R_n$ eliminates a considerable amount of the error present in the respective approximations. In a similar way, it makes sense to think about averaging $M_n$ and $T_n$ in order to generate a still more accurate approximation.

We've just observed that $M_n$ is typically about twice as accurate as $T_n\text{.}$ This leads to an approximation method known as Simpson's Rule 14Thomas Simpson was an 18th century mathematician; his idea was to extend the Trapezoid rule, but rather than using straight lines to build trapezoids, to use quadratic functions to build regions whose area was bounded by parabolas (whose areas he could find exactly). Simpson's Rule is often developed from the more sophisticated perspective of using interpolation by quadratic functions. which is a weighted average of the Midpoint and Trapezoid approximations.

###### Simpson's Rule

The Simpson's Rule approximation $S_{2n}$ of the area $\int_a^b f(x) \ dx$ is the weighted average

$$S_{2n} = \frac{2M_n + T_n}{3}\text{.}\label{E-Simpson}\tag{5.19}$$

where $M_n$ and $T_n$ are the Midpoint and Trapezoid rule approximations using $n$ subintervals.

Note that we use $S_{2n}$ rather that $S_n$ since the $n$ points the Midpoint Rule uses are different from the $n$ points the Trapezoid Rule uses, and thus Simpson's Rule is using $2n$ points at which to evaluate the function. We build upon the results in Table5.84 to see the approximations generated by Simpson's Rule. In particular, in Table5.85, we include all of the results in Table5.84, but include additional results for $S_8 = \frac{2M_4 + T_4}{3}$ and $S_{16} = \frac{2M_8 + T_8}{3}\text{.}$

The results seen in Table5.85 are striking. If we consider the $S_{16}$ approximation of $\int_1^2 \frac{1}{x^2} \, dx\text{,}$ the error is only $E_{S,16} = 0.0000019434\text{.}$ By contrast, $L_8 = 0.5491458502\text{,}$ so the error of that estimate is $E_{L,8} = -0.0491458502\text{.}$ Moreover, we observe that generating the approximations for Simpson's Rule is almost no additional work: once we have $L_n\text{,}$ $R_n\text{,}$ and $M_n$ for a given value of $n\text{,}$ it is a simple exercise to generate $T_n\text{,}$ and from there to calculate $S_{2n}\text{.}$ Finally, note that the error in the Simpson's Rule approximations of $\int_0^1 (1-x^2) \, dx$ is zero!15Similar to how the Midpoint and Trapezoid approximations are exact for linear functions, Simpson's Rule approximations are exact for quadratic and cubic functions. See additional discussion on this issue later in the section and in the exercises.

These rules are not only useful for approximating definite integrals such as $\int_0^1 e^{-x^2} \, dx\text{,}$ for which we cannot find an elementary antiderivative of $e^{-x^2}\text{,}$ but also for approximating definite integrals when we are given a function through a table of data.

###### Example5.86

A car traveling along a straight road is braking and its velocity is measured at several different points in time, as given in the following table. Assume that $v$ is continuous, always decreasing, and always decreasing at a decreasing rate, as is suggested by the data.

 seconds, $t$ Velocity in ft/sec, $v(t)$ $0$ $100$ $0.3$ $99$ $0.6$ $96$ $0.9$ $90$ $1.2$ $80$ $1.5$ $50$ $1.8$ $0$
1. Plot the given data on the set of axes provided in Figure5.88 with time on the horizontal axis and the velocity on the vertical axis.

2. What definite integral will give you the exact distance the car traveled on $[0,1.8]\text{?}$

3. Estimate the total distance traveled on $[0,1.8]$ by computing $L_3\text{,}$ $R_3\text{,}$ and $T_3\text{.}$ Which of these under-estimates the true distance traveled?

4. Estimate the total distance traveled on $[0,1.8]$ by computing $M_3\text{.}$ Is this an over- or under-estimate? Why?

5. Using your results from (c) and (d), improve your estimate further by using Simpson's Rule.

6. What is your best estimate of the average velocity of the car on $[0,1.8]\text{?}$ Why? What are the units on this quantity?

Hint
1. Plot the data.

2. What are the units of $v(t) \cdot \Delta t\text{?}$

3. Recall the standard rules for sums that produce $L_3\text{,}$ $R_3\text{,}$ $T_3\text{.}$

4. Think about concavity to decide if $M_3$ is an over- or under-estimate.

5. Recall how $S_3$ is a weighted average of $T_3$ and $M_3\text{.}$

6. Simpson's Rule gives the best estimate for a function of consistent concavity.

1. Plot the data.

2. $\int_0^{1.8} v(t) dt\text{.}$

3. \begin{align*} L_3 \amp = 165.6 \text{ ft } \amp R_3 \amp = 105.6 \text{ ft } \amp T_3 \amp = 135.6 \text{ ft }\text{.} \end{align*}

$R_3$ and $T_3$ are underestimates.

4. $M_3 = 143.4 \text{ ft }$ ; overestimate.

5. $S_6 = 140.8 \text{ ft } \text{.}$

6. Simpson's rule gives the best approximation of the distance traveled, $\int_0^{1.8} v(t) dt \approx 140.8 \text{ ft }\text{.}$

Solution
1. Plot the data.

2. Since the velocity is always positive, the definite integral that will give the exact distance traveled by the car on the interval $[0, 1.8]$ is

\begin{equation*} \int_0^{1.8} v(t) dt\text{.} \end{equation*}
3. The estimates of $\int_0^{1.8} v(t) dt$ are

\begin{align*} L_3 \amp = 165.6 \text{ ft } \amp R_3 \amp = 105.6 \text{ ft } \amp T_3 \amp = 135.6 \text{ ft }\text{.} \end{align*}

$R_3$ is an underestimate of the distance traveled since $v(t)$ is decreasing. $T_3$ is an underestimate of the distance traveled since $v(t)$ is concave down.

4. Another estimate of the distance traveled is

\begin{equation*} M_3 = 143.4 \text{ ft }\text{.} \end{equation*}

This is an overestimate since $v(t)$ is concave down.

5. For Simpson's Rule, we see that

\begin{equation*} S_6 = \frac{2}{3}M_3 + \frac{1}{3}T_3 = 140.8 \text{ ft }\text{.} \end{equation*}
6. Simpson's rule gives the best approximation of the distance traveled since it is a weighted average of the midpoint and trapezoid rules and uses more information about the velocity than the other methods. The units on each of the estimates, including Simpson's Rule, are "feet", since ft/sec $\cdot$ sec = ft. Thus, the best approximation we have generated is that $\int_0^{1.8} v(t) dt \approx 140.8 \text{ ft }\text{.}$

### SubsectionComparing $L_n\text{,}$ $R_n\text{,}$ $T_n\text{,}$ $M_n\text{,}$ and $S_{2n}\text{.}$

As we conclude our discussion of numerical approximation of definite integrals, it is important to summarize general trends in how the various rules over- or under-estimate the true value of a definite integral, and by how much. To revisit some past observations and see some new ones, we consider the following example.

###### Example5.89

Consider the functions $f(x) = 2-x^2\text{,}$ $g(x) = 2-x^3\text{,}$ and $h(x) = 2-x^4\text{,}$ all on the interval $[0,1]\text{.}$ For each of the questions that require a numerical answer in what follows, write your answer exactly in fraction form.

1. On the three sets of axes provided in Figure5.90, sketch a graph of each function on the interval $[0,1]\text{,}$ and compute $L_1$ and $R_1$ for each. What do you observe?

2. Compute $M_1$ for each function to approximate $\int_0^1 f(x) \,dx\text{,}$ $\int_0^1 g(x) \,dx\text{,}$ and $\int_0^1 h(x) \,dx\text{,}$ respectively.

3. Compute $T_1$ for each of the three functions, and hence compute $S_2$ for each of the three functions.

4. Evaluate each of the integrals $\int_0^1 f(x) \,dx\text{,}$ $\int_0^1 g(x) \,dx\text{,}$ and $\int_0^1 h(x) \,dx$ exactly using the First FTC.

5. For each of the three functions $f\text{,}$ $g\text{,}$ and $h\text{,}$ compare the results of $L_1\text{,}$ $R_1\text{,}$ $M_1\text{,}$ $T_1\text{,}$ and $S_2$ to the true value of the corresponding definite integral. What patterns do you observe?

Hint
1. For each estimate, just one function evaluation is needed.

2. Use the midpoint rule with $n=1\text{.}$

3. Remember that both the trapezoid and Simpson's rule can be executed using (weighted) averages of known values.

4. Find antiderivatives to evaluate the integrals exactly.

5. Think about trends in over- and under-estimates.

1. For $L_1$ and $T_1\text{:}$

The values of $L_1$ and $R_1$ are the same for all three.

2. For the $M_1\text{,}$

3. For $T_1$ and $S_2\text{,}$

4. \begin{align*} \int_0^1 f(x) dx \amp = \frac{5}{3} \amp \int_0^1 g(x) dx \amp = \frac{7}{4} \amp \int_0^1 h(x) dx \amp = \frac{9}{5} \end{align*}
5. Left endpoint rule results are overestimates; right endpoint rules are underestimates; midpoint rules are overestimates; trapezoid rules are underestimates. Simpson's rule is exact for both $f$ and $g\text{,}$ while a slight overestimate of $\int_0^1 h(x) dx\text{.}$

Solution
1. For the left and right endpoint rules, we see that

Thus, we observe that despite the fact the functions are all different, the values of $L_1$ and $R_1$ are the same for all three.

2. For the midpoint rule, we find that

3. For the trapezoid rule and Simpson's rule,

4. The exact values of the three definite integrals are

\begin{align*} \int_0^1 f(x) dx \amp = \frac{5}{3} \amp \int_0^1 g(x) dx \amp = \frac{7}{4} \amp \int_0^1 h(x) dx \amp = \frac{9}{5}\\ \amp \approx 1.6667 \amp \amp = 1.75 \amp \amp = 1.8 \end{align*}
5. We observe that each of the left endpoint rule results are overestimates, each of the right endpoint rules are underestimates, each of the midpoint rules are overestimates, and each of the trapezoid rules are underestimates. These results hold because each of the three functions are both decreasing and concave down. For Simpson's rule, we see that the result is exact for both $f$ and $g\text{,}$ while Simpson's rule is a slight overestimate of $\int_0^1 h(x) dx\text{.}$

The results seen in Example5.89 generalize nicely. For instance, if $f$ is decreasing on $[a,b]\text{,}$ $L_n$ will overestimate the exact value of $\int_a^b f(x) \,dx\text{,}$ and if $f$ is concave down on $[a,b]\text{,}$ $M_n$ will overestimate the exact value of the integral. An excellent exercise is to write a collection of scenarios of possible function behavior, and then categorize whether each of $L_n\text{,}$ $R_n\text{,}$ $T_n\text{,}$ and $M_n$ is an over- or under-estimate.

Finally, we make two important notes about Simpson's Rule. When T.Simpson first developed this rule, his idea was to replace the function $f$ on a given interval with a quadratic function that shared three values with the function $f\text{.}$ In so doing, he guaranteed that this new approximation rule would be exact for the definite integral of any quadratic polynomial. In one of the pleasant surprises of numerical analysis, it turns out that even though it was designed to be exact for quadratic polynomials, Simpson's Rule is exact for any cubic polynomial: that is, if we are interested in an integral such as $\int_2^5 (5x^3 - 2x^2 + 7x - 4)\, dx\text{,}$ the approximation $S_{2n}$ will always be exact, regardless of the value of $n\text{.}$ This is just one more piece of evidence that shows how effective Simpson's Rule is as an approximation tool for estimating definite integrals.16One reason that Simpson's Rule is so effective is that $S_{2n}$ benefits from using $2n+1$ points of data. Because it combines $M_n\text{,}$ which uses $n$ midpoints, and $T_n\text{,}$ which uses the $n+1$ endpoints of the chosen subintervals, $S_{2n}$ takes advantage of the maximum amount of information we have when we know function values at the endpoints and midpoints of $n$ subintervals.

### SubsectionSummary

• For a definite integral such as $\int_0^1 e^{-x^2} \, dx$ when we cannot use the First Fundamental Theorem of Calculus because the integrand lacks an elementary algebraic antiderivative, we can estimate the integral's value by using a sequence of Riemann sum approximations. Typically, we start by computing $L_n\text{,}$ $R_n\text{,}$ and $M_n$ for one or more chosen values of $n\text{.}$

• The Trapezoid Rule, which estimates $\int_a^b f(x) \, dx$ by using trapezoids, rather than rectangles, can also be viewed as the average of Left and Right Riemann sums. That is, $T_n = \frac{1}{2}(L_n + R_n)\text{.}$

• The Midpoint Rule is typically twice as accurate as the Trapezoid Rule, and the signs of the respective errors of these rules are opposites. Hence, by taking the weighted average $S_{2n} = \frac{2M_n + T_n}{3}\text{,}$ we can build a much more accurate approximation to $\int_a^b f(x) \, dx$ by using approximations we have already computed. The rule for $S_{2n}$ is known as Simpson's Rule, which can also be developed by approximating a given continuous function with pieces of quadratic polynomials.

• By understanding the approximation rule chosen, and the properties of the function (i.e. whether it is increasing or decreasing, or concave up or down on the interval in question), we can say whether the approximation is an over or under-estimate of the actual value.

### SubsectionExercises

Consider the definite integral $\int_0^1 x \tan(x) \, dx\text{.}$

1. Explain why this integral cannot be evaluated exactly by using either $u$-substitution or by integrating by parts.

2. Using appropriate subintervals, compute $L_4\text{,}$ $R_4\text{,}$ $M_4\text{,}$ $T_4\text{,}$ and $S_8\text{.}$

3. Which of the approximations in (b) is an over-estimate to the true value of $\int_0^1 x \tan(x) \, dx\text{?}$ Which is an under-estimate? How do you know?

For an unknown function $f(x)\text{,}$ the following information is known.

• $f$ is continuous on $[3,6]\text{;}$

• $f$ is either always increasing or always decreasing on $[3,6]\text{;}$

• $f$ has the same concavity throughout the interval $[3,6]\text{;}$

• As approximations to $\int_3^6 f(x) \, dx\text{,}$ $L_4 = 7.23\text{,}$ $R_4 = 6.75\text{,}$ and $M_4 = 7.05\text{.}$

1. Is $f$ increasing or decreasing on $[3,6]\text{?}$ What data tells you?

2. Is $f$ concave up or concave down on $[3,6]\text{?}$ Why?

3. Determine the best possible estimate you can for $\int_3^6 f(x) \, dx\text{,}$ based on the given information.

The rate at which water flows through Table Rock Dam on the White River in Branson, MO, is measured in thousands of cubic feet per second (TCFS). As engineers open the floodgates, flow rates are recorded according to the following chart.

1. What definite integral measures the total volume of water to flow through the dam in the 60 second time period provided by the table above?

2. Use the given data to calculate $M_n$ for the largest possible value of $n$ to approximate the integral you stated in (a). Do you think $M_n$ over- or under-estimates the exact value of the integral? Why?

3. Approximate the integral stated in (a) by calculating $S_n$ for the largest possible value of $n\text{,}$ based on the given data.

4. Compute $\frac{1}{60} S_n$ and $\frac{2000+2100+2400+3000+3900+5100+6500}{7}\text{.}$ What quantity do both of these values estimate? Which is a more accurate approximation?


# Difference between revisions of "2020 AIME I Problems/Problem 5"

## Problem

Six cards numbered $1$ through $6$ are to be lined up in a row. Find the number of arrangements of these six cards where one of the cards can be removed leaving the remaining five cards in either ascending or descending order.

## Solution 1

Realize that any sequence that works (ascending) can be reversed for descending, so we can just take the amount of sequences that satisfy the ascending condition and multiply by two.

If we choose any of the numbers $1$ through $6$, there are five other spots to put them, so we get $6 \cdot 5 = 30$. However, we overcount some cases. Take the example of $132456$. We overcount this case because we can remove the $3$ or the $2$. Therefore, any cases with two adjacent numbers swapped is overcounted, so we subtract $5$ cases (namely, $213456, 132456, 124356, 123546, 123465$,) to get $30-5=25$, but we have to add back one more for the original case, $123456$. Therefore, there are $26$ cases. Multiplying by $2$ gives the desired answer, $\boxed{052}$.

~molocyxu

## Solution 2 (Inspired by 2018 CMIMC Combo Round)

Similar to above, a $1-1$ correspondence between ascending and descending is established by subtracting each number from $7$.

We note that the given condition is equivalent to "cycling" $123456$ for a contiguous subset of it. For example,

$12(345)6 \rightarrow 125346, 124536$

It's not hard to see that no overcount is possible, and that the cycle is either $1$ "right" or $1$ "left." Therefore, we consider how many elements we flip by. If we flip $1$ or $2$ such elements, then there is one way to cycle them. Otherwise, we have $2$ ways. Therefore, the total number of ascending is $1 + 5 + 2(4 + 3 + 2 + 1) = 26$, and multiplying by two gives $\boxed{052}.$

~awang11

## Solution 3

Similarly to above, we find the number of ascending arrangements and multiply by 2.

We can choose $5$ cards to be the ascending cards, therefore leaving $6$ places to place the remaining card. There are $\binom{6}{5}\cdot 6=36$ to do this. However, since the problem is asking for the number of arrangements, we overcount cases such as $123456$. Notice that the only arrangements that overcount are $123456$ (case 1) or if two adjacent numbers of $123456$ are switched (case 2).

$\text{Case 1: }$ This arrangement is counted $6$ times. Each time it is counted for any of the $5$ numbers selected. Therefore we need to subtract $5$ cases of overcounting.

$\text{Case 2: }$ Each time $2$ adjacent numbers of switched, there is one overcount. For example, if we have $213456$, both $1$ or $2$ could be removed. Since there are $5$ possible switches, we need to subtract $5$ cases of overcounting.

Therefore, we have $36-5-5=26$ total arrangements of ascending numbers. We multiply by two (for descending) to get the answer of $\boxed{052}.$

~PCChess

## Solution 4 (No Overcounting)

Like in previous solutions, we will count the number of ascending arrangements and multiply by 2.

First, consider the arrangement 1-2-3-4-5-6. That gives us 1 arrangement which works.

Next, we can switch two adjacent cards. There are 5 ways to pick two adjacent cards, so this gives us 5 arrangements.

Now, we can "cycle" 3 adjacent cards. For example, 1-2-3 becomes 2-3-1 which becomes 3-1-2. There are 4 ways to pick a set of 3 adjacent cards, so this gives us 4x2=8 arrangements.

Cycling 4 adjacent cards, we get the new arrangements 2-3-4-1 (which works,) 3-4-1-2 (which doesn't work,) and 4-1-2-3 (which does work.) We get 6 arrangements.

Similarly, when cycling 5 cards, we find 2x2=4 arrangements, and when cycling 6 cards, we find 2x1=2 arrangements.

Adding, we figure out that there are 1+5+8+6+4+2=26 ascending arrangements. Multiplying by 2, we get the answer $\boxed{052}.$

~i8Pie

## Solution 5 (Official MAA 1)

First count the number of permutations of the cards such that if one card is removed, the remaining cards will be in ascending order. There is $1$ such permutation where all the cards appear in order: $123456.$ There are $5$ such permutations where two adjacent cards are interchanged, as in $124356.$ The other such permutations arise from removing one card from $123456$ and placing it in a position at least two away from its starting location. There are $4$ such positions to place each of the cards numbered $1$ and $6,$ and $3$ such positions for each of the cards numbered $2, 3, 4,$ and $5.$ This accounts for $2\cdot4 + 4\cdot3 =20$ permutations. Thus there are $1 + 5 + 20 = 26$ permutations where one card can be removed so that the remaining cards are in ascending order. There is an equal number of permutations that result in the cards' being in descending order. This gives the total $26 + 26 = \boxed{52}$.

## Solution 6 (Official MAA 2)

More generally, suppose there are $n \geq 4$ cards numbered $1, 2, 3, \dots, n$ arranged in ascending order. If any one of the $n$ cards is removed and placed in one of the $n$ positions in the arrangement, the resulting permutation will have the property that one card can be removed so that the remaining cards are in ascending order. This accounts for $n\cdot n = n^2$ permutations. However, the original ascending order has been counted $n$ times, and each order that arises by switching two neighboring cards has been counted twice. Hence the number of arrangements where one card can be removed resulting in the remaining cards' being in ascending order is $n^2-(n-1)-(n-1)=(n-1)^2+1.$ When $n = 6$, this is $(6-1)^2+1 = 26$, and the final answer is $2\cdot26 = \boxed{52}$.

## Solution 7 (Casework)

For ascending, if the $1$ goes in anything but the first two slots, the rest of the numbers have to go in ascending from $2$, which are $4$ cases if there are $6$ cards. If $1$ goes in the second spot, then you can put any of the rest in the first slot but then the rest are determined, so in the case of $6$ cards, that gives $5$ more. If $1$ goes in the first slot, that means that you are doing the same problem with $n-1$ cards. So the recursion is $a_n=(n-2)+(n-1)+a_{n-1}$. There's $a_1=1$ and $a_2=2$, so you get $a_3=2+3=5$, $a_4=5+5=10$, $a_5=7+10=17$, and $a_6=9+17=26$. Or you can see that $a_n=(n-1)^2+1$. We double to account for descending and get $\boxed{052}$.

~ahclark11

## Solution 8 (Symmetry and Case Study)

First, we know that ascending order and descending order are symmetrical to each other (namely, if we get 132456 where after we take out 3, it will be one scenario; and if we flip it and write 654231, it will be another scenario)

Thus, we only need to consider either descending or ascending and then times 2. WLOG let us consider ascending order

Case 1: after we take out 1, the rest will be in ascending order

2 3 4 5 6

1 can be tucked in any one of the 6 spaces, thus there are 6 scenarios.

Case 2: after we take out 2, the rest will be in ascending order

1 3 4 5 6

notice that if we put 2 next to 1 (to the right or to the left of 1), it will be an overcount, so there are only 4 cases for 2

It is easy to see that this is the same for 3, 4, 5, and 6.

Thus, in total, we have $$(6+4\times5)\times2=\boxed{052}$$ ~Adali


# Prove: $\frac{a+c}{b+d}$ lies between $\frac{a}{b}$ and $\frac{c}{d}$ (for positive $a$, $b$, $c$, $d$)

I am looking for proof that, if you take any two different fractions and add the numerators together then the denominators together, the answer will always be a fraction that lies between the two original fractions.

Would be grateful for any suggestions!

• Not to be picky, but if we consider the fractions $a/b,c/d$ with $a=b=c=1$ and $d=-2$, then $(a+c)/(b+d)=-2$, which does not lie between $a/b=1$ and $c/d=-1/2$.... – Barry Cipra Apr 27 '16 at 18:55
• Good point Barry. Let's say that a, b, c and d are all positive integers. – Joeywald Apr 27 '16 at 19:24
• mathsguy, not a lot as "proof" is new to me. I know that adding the same number to the top and bottom of a fraction moves the derived fraction closer to 1 and that adding two fractions as above gives a resultant fraction between the two, but I can't prove why this happens. – Joeywald Apr 27 '16 at 19:33

Suppose we have positive $a,b,c,d$ with $\frac{a}{b}\ge \frac{c}{d}$. Then multiplying through by $bd$ we get $ad\ge bc$. Adding $ab$ to both sides we get $a(b+d)\ge b(a+c)$. Dividing by $b(b+d)$, we get $\frac{a}{b}\ge\frac{a+c}{b+d}$.

Similarly, add $cd$ to both sides of $ad\ge bc$ to get $d(a+c)\ge c(b+d)$. Dividing by $d(b+d)$ we get $\frac{a+c}{b+d}\ge \frac{c}{d}$.

Assuming $a,b,c,d\gt0$, we have

\begin{align} {a\over b}\lt{a+c\over b+d}\lt{c\over d}&\iff a(b+d)\lt b(a+c)\quad\text{and}\quad(a+c)d\lt(b+d)c\\ &\iff ad\lt bc\quad\text{and}\quad ad\lt bc\\ &\iff ad\lt bc\\ &\iff {a\over b}\lt{c\over d} \end{align}

• One usually starts with the premise and ends with the conclusion... No? – Najib Idrissi Jun 7 '16 at 17:38
• @NajibIdrissi If it's $“\Leftrightarrow”$ signs the whole way through, it shouldn't matter. – Akiva Weinberger Jun 7 '16 at 17:47
• @AkivaWeinberger Sure, but I think it's easier to read and looks more sound if you put it in the other order. But of course from a logical point of view, equivalence of propositions is symmetrical... – Najib Idrissi Jun 7 '16 at 18:09

Here is another way that uses calculus:

Let $\phi(t) = {(1-t)a+t c \over (1-t)b + t d}$ and note that $\phi(0) = {a \over b}, \phi(1) = {c \over d}$. Furthermore, $\phi'(t) = {bc-ad \over ((1-t)b + t d )^2}$. Since $ad < bc$, we see that $\phi$ is increasing, and so $\phi(0) \le \phi({1 \over 2}) \le \phi(1)$. Since $\phi({1 \over 2}) = {a+c \over b+d}$, we have the desired result.

Assume that $b,d >0$. Note that $$\frac{a+c}{b+d} = \frac{b}{b+d}\frac{a}{b} +\frac{d}{b+d}\frac{c}{d}.$$ Remark that $0<\frac{b}{b+d}<1$ and the same for $\frac{d}{b+d}$. Hence you have written $\frac{a+b}{c+d}$ as a convex combination of $\frac{a}{b}$ and $\frac{c}{d}$ so you get $$\frac{a}{b} < \frac{a+c}{b+d} < \frac{c}{d}.$$

Here's one way to look at it:

You're taking a class. Suppose you get $a$ points out of $b$ possible on Quiz 1, and $c$ points out of $d$ possible on Quiz 2.

Your overall points are $a+c$ out of $b+d$ possible. And your overall percentage should be between your lower quiz score and your higher quiz score.

• The question asks for "proof". – AlohaSine Apr 30 '16 at 23:54
• @MathematicsStudent1122 Actually the presenter asked for suggestions. One could use this idea as the basis for a proof. – paw88789 May 1 '16 at 2:49

Hint $\$ The mediant $(a\!+\!b)/(c\!+\!d)\,$ is the slope of the diagonal of the parallelogram with vector sides $(b,a),\ (d,c).\:$ But the slope of the diagonal lies between the slopes of the sides.


# Trapezoid Rule

import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline

## Trapezoids

The definite integral of $f(x)$ is equal to the (net) area under the curve $y=f(x)$ over the interval $[a,b]$. Riemann sums approximate definite integrals by using sums of rectangles to approximate the area.

The trapezoid rule gives a better approximation of a definite integral by summing the areas of the trapezoids connecting the points

$$(x_{i-1},0), (x_i,0), (x_{i-1},f(x_{i-1})), (x_i,f(x_i))$$

for each subinterval $[x_{i-1},x_i]$ of a partition. Note that the area of each trapezoid is the sum of a rectangle and a triangle

$$(x_i - x_{i-1}) f(x_{i-1}) + \frac{1}{2}(x_i - x_{i-1}) (f(x_i) - f(x_{i-1})) = \frac{1}{2}(f(x_i) + f(x_{i-1}))(x_i - x_{i-1})$$

For example, we can use a single trapezoid to approximate:

$$\int_0^1 e^{-x^2} \, dx$$

First, let's plot the curve $y = e^{-x^2}$ and the trapezoid on the interval $[0,1]$:

x = np.linspace(-0.5,1.5,100)
y = np.exp(-x**2)
plt.plot(x,y)

x0 = 0; x1 = 1;
y0 = np.exp(-x0**2); y1 = np.exp(-x1**2);
plt.fill_between([x0,x1],[y0,y1])

plt.xlim([-0.5,1.5]); plt.ylim([0,1.5]);
plt.show()

Approximate the integral by the area of the trapezoid:

A = 0.5*(y1 + y0)*(x1 - x0)
print("Trapezoid area:", A)
Trapezoid area: 0.6839397205857212

## Definition

The trapezoid rule for $N$ subintervals of $[a,b]$ of equal length is

$$T_N(f) = \frac{\Delta x}{2} \sum_{i=1}^N (f(x_i) + f(x_{i-1}))$$

where $\Delta x = (b - a)/N$ is the length of the subintervals and $x_i = a + i \Delta x$.

Notice that the trapezoid is the average of the left and right Riemann sums

$$T_N(f) = \frac{\Delta x}{2} \sum_{i=1}^N (f(x_i) + f(x_{i-1})) = \frac{1}{2} \left( \sum_{i=1}^N f(x_i) \Delta x + \sum_{i=1}^N f(x_{i-1}) \Delta x \right)$$

## Error Formula

When computing integrals numerically, it is essential to know how good our approximations are. Notice in the theorem below that the error formula is inversely proportional to $N^2$. This means that the error decreases much faster with larger $N$ compared to Riemann sums.

Theorem. Let $T_N(f)$ denote the trapezoid rule

$$T_N(f) = \frac{\Delta x}{2} \sum_{i=1}^N (f(x_i) + f(x_{i-1}))$$

where $\Delta x = (b-a)/N$ and $x_i = a + i \Delta x$. The error bound is

$$E_N^T(f) = \left| \ \int_a^b f(x) \ dx - T_N(f) \ \right| \leq \frac{(b-a)^3}{12 N^2} K_2$$

where $\left| \ f''(x) \, \right| \leq K_2$ for all $x \in [a,b]$.

## Implementation

Let's write a function called trapz which takes input parameters $f$, $a$, $b$ and $N$ and returns the approximation $T_N(f)$. Furthermore, let's assign default value $N=50$.

def trapz(f,a,b,N=50):
'''Approximate the integral of f(x) from a to b by the trapezoid rule.

The trapezoid rule approximates the integral \int_a^b f(x) dx by the sum:
(dx/2) \sum_{k=1}^N (f(x_k) + f(x_{k-1}))
where x_k = a + k*dx and dx = (b - a)/N.

Parameters
----------
f : function
Vectorized function of a single variable
a , b : numbers
Interval of integration [a,b]
N : integer
Number of subintervals of [a,b]

Returns
-------
float
Approximation of the integral of f(x) from a to b using the
trapezoid rule with N subintervals of equal length.

Examples
--------
>>> trapz(np.sin,0,np.pi/2,1000)
0.9999997943832332
'''
x = np.linspace(a,b,N+1) # N+1 points make N subintervals
y = f(x)
y_right = y[1:] # right endpoints
y_left = y[:-1] # left endpoints
dx = (b - a)/N
T = (dx/2) * np.sum(y_right + y_left)
return T

Let's test our function on an integral where we know the answer

$$\int_0^{\pi/2} \sin x \ dx = 1$$

trapz(np.sin,0,np.pi/2,1000)
0.9999997943832332

Let's test our function again:

$$\int_0^1 3 x^2 \ dx = 1$$

trapz(lambda x : 3*x**2,0,1,10000)
1.0000000050000002

And once more:

$$\int_0^1 x \ dx = \frac{1}{2}$$

trapz(lambda x : x,0,1,1)
0.5

## scipy.integrate.trapz

The SciPy subpackage scipy.integrate contains several functions for approximating definite integrals and numerically solving differential equations. Let's import the subpackage under the name spi.

import scipy.integrate as spi

The function scipy.integrate.trapz computes the approximation of a definite by the trapezoid rule. Consulting the documentation, we see that all we need to do it supply arrays of $x$ and $y$ values for the integrand and scipy.integrate.trapz returns the approximation of the integral using the trapezoid rule. The number of points we give to scipy.integrate.trapz is up to us but we have to remember that more points gives a better approximation but it takes more time to compute!

## Examples

### Arctangent

Let's plot the trapezoids for $\displaystyle f(x)=\frac{1}{1 + x^2}$ on $[0,5]$ with $N=10$.

f = lambda x : 1/(1 + x**2)
a = 0; b = 5; N = 10

# x and y values for the trapezoid rule
x = np.linspace(a,b,N+1)
y = f(x)

# X and Y values for plotting y=f(x)
X = np.linspace(a,b,100)
Y = f(X)
plt.plot(X,Y)

for i in range(N):
xs = [x[i],x[i],x[i+1],x[i+1]]
ys = [0,f(x[i]),f(x[i+1]),0]
plt.fill(xs,ys,'b',edgecolor='b',alpha=0.2)

plt.title('Trapezoid Rule, N = {}'.format(N))
plt.show()

Let's compute the sum of areas of the trapezoids:

T = trapz(f,a,b,N)
print(T)
1.3731040812301096

We know the exact value

$$\int_0^5 \frac{1}{1 + x^2} dx = \arctan(5)$$

and we can compare the trapezoid rule to the value

I = np.arctan(5)
print(I)
1.373400766945016
print("Trapezoid Rule Error:",np.abs(I - T))
Trapezoid Rule Error: 0.00029668571490626405

### Approximate ln(2)

Find a value $N$ which guarantees that the trapezoid rule approximation $T_N(f)$ of the integral

$$\int_1^2 \frac{1}{x} \, dx = \ln(2)$$

satisfies $E_N^T(f) \leq 10^{-8}$.

For $f(x) = \frac{1}{x}$, we compute $f''(x) = \frac{2}{x^3} \leq 2$ for all $x \in [1,2]$ therefore the error formula implies

$$\left| \, \int_1^2 \frac{1}{x} \, dx - T_N(f) \, \right| \leq \frac{2}{12N^2}$$

Then $E_N^T \leq 10^{-8}$ is guaranteed if $\frac{1}{6N^2} \leq 10^{-8}$ which implies

$$\frac{10^4}{\sqrt{6}} \leq N$$

10**4/np.sqrt(6)
4082.4829046386303

We need 4083 subintervals to guarantee $E_N^T(f) \leq 10^{-8}$. Compute the approximation using our own implementation of the trapezoid rule:

approximation = trapz(lambda x : 1/x,1,2,4083)
print(approximation)
0.6931471843089954

We could also use scipy.integrate.trapz to get the exact same result:

N = 4083
x = np.linspace(1,2,N+1)
y = 1/x
approximation = spi.trapz(y,x)
print(approximation)
0.6931471843089955

Let's verify that this is within $10^{-6}$:

np.abs(approximation - np.log(2)) < 10**(-8)
True

Success! However, a natural question arises: what is the actual smallest $N$ such that the trapezoid rule gives the estimate of $\ln (2)$ to within $10^{-8}$?

for n in range(1,4083):
approx = trapz(lambda x : 1/x,1,2,n)
if np.abs(approx - np.log(2)) < 10e-8:
print("Accuracy achieved at N =",n)
break
Accuracy achieved at N = 791

### Fresnel Integral

Fresnel integrals are examples of nonelementary integrals: antiderivatives which cannot be written in terms of elementary functions. There are two types of Fresnel integrals:

$$S(t) = \int_0^t \sin(x^2) dx \ \ \text{and} \ \ C(t) = \int_0^t \cos(x^2) dx$$

Use the trapezoid rule to approximate the Fresnel integral

$$S(1) = \int_0^1 \sin(x^2) dx$$

such that the error is less than $10^{-5}$.

Compute the derivatives of the integrand

$$f(x) = \sin(x^2) \ \ , \ \ f'(x) = 2x\cos(x^2)$$

$$f''(x) = 2\cos(x^2) - 4x^2\sin(x^2) \ \ , \ \ f'''(x) = -12x\sin(x^2) - 8x^3\cos(x^2)$$

Since $f'''(x) \leq 0$ for $x \in [0,1]$, we see that $f''(x)$ is decreasing on $[0,1]$. Values of $f''(x)$ at the endpoints of the interval are

x = 0
2*np.cos(x**2) - 4*x**2*np.sin(x**2)
2.0
x = 1
2*np.cos(x**2) - 4*x**2*np.sin(x**2)
-2.2852793274953065

Therefore $\left| \, f''(x) \, \right| \leq 2.2852793274953065$ for $x \in [0,1]$. Use the error bound formula to find a good choice for $N$

$$\frac{(b-a)^3}{12 N^2} K_2 \leq 10^{-5} \Rightarrow \sqrt{\frac{10^5(2.2852793274953065)}{12}} \leq N$$

np.sqrt(10**5 * 2.2852793274953065 / 12)
137.9999796949051

Let's compute the integral using the trapezoid rule with $N=138$ subintervals

x = np.linspace(0,1,139)
y = np.sin(x**2)
I = spi.trapz(y,x)
print(I)
0.31027303032220394

Therefore the Fresnel integral $S(1)$ is approximately

$$S(1) = \int_0^1 \sin(x^2) \, dx \approx 0.310273030322$$

with error less than $10^{-5}$.

### Logarithmic Integral

The Eulerian logarithmic integral is another nonelementary integral

$$\mathrm{Li}(t) = \int_2^t \frac{1}{\ln x} dx$$

Let's compute $Li(10)$ such that the error is less than $10^{-4}$. Compute derivatives of the integrand

$$f(x) = \frac{1}{\ln x} \ \ , \ \ f'(x) = -\frac{1}{x(\ln x)^2} \ \ , \ \ f''(x) = \frac{\ln x + 2 }{x^2(\ln x)^3}$$

Plot $f''(x)$ on the interval $[2,10]$.

a = 2
b = 10
x = np.linspace(a,b,100)
y = (np.log(x) + 2) / (x**2 * np.log(x)**3)
plt.plot(x,y)
plt.show()

Clearly $f''(x)$ is decreasing on $[2,10]$ (and bounded below by 0) therefore the absolute maximum occurs at the left endpoint:

$$\left| \, f''(x) \, \right| \leq \frac{\ln (2) + 2}{4 \ln (2)^3}$$

for $x \in [2,10]$ and we compute

K2 = (np.log(2) + 2)/(4*np.log(2)**3)
print(K2)
2.021732598829855

Use the error formula:

$$\frac{(b-a)^3}{12 N^2} K_2 \leq 10^{-4} \Rightarrow \frac{8^3}{12 N^2} 2.021732598829855 \leq 10^{-4} \Rightarrow \sqrt{ \frac{8^3 10^4}{12} 2.021732598829855} \leq N$$

np.sqrt(8**3 * 10**4 * 2.021732598829855 / 12)
928.7657986995814

Compute the trapzoid rule with $N=929$

N = 929
x = np.linspace(a,b,N+1)
y = 1/np.log(x)
I = spi.trapz(y,x)
print(I)
5.120442039184057

Therefore the Eulerian logarithmic integral is

$$\mathrm{Li}(10) = \int_2^{10} \frac{1}{\ln x} dx \approx 5.121065367200469$$

such that the error is less than $10^{-4}$.

## Exercises

1. Let $f(x) = x^x$ and note that

$$f'(x) = x^{x} \left(\log{\left(x \right)} + 1\right) \ , \ f''(x) = x^{x} \left(\log{\left(x \right)} + 1\right)^{2} + x^{x-1}$$

Plot the function $f''(x)$ and use that information to compute $T_N(f)$ for the integral

$$\int_1^2 x^x \, dx$$

such that $E_N^T(f) \leq 10^{-3}$.

2. Consider the integral

$$\int_0^1 \ln(1+x^2) \, dx$$

and note that

$$f(x) = \ln(1 + x^2) \hspace{1in} f'(x) = \frac{2x}{1 + x^2}$$ $$f''(x) = 2 \left( \frac{1 - x^2}{1 + x^2} \right) \hspace{1in} f'''(x) = 4x \frac{x^2 - 3}{(x^2 + 1)^3}$$

Without plotting the functions $f(x)$, $f'(x)$, $f''(x)$ or $f'''(x)$, find a value $N$ such that $E_N^T(f) \leq 10^{-6}$.


# Path on a chessboard

Consider a chess board and a pawn. The game is simple (and I'm sure you have all heard it before), pawn wants to move from position (1,1), or the bottom left corner, all the way to (n,n), or the upper right corner. We are asked to find all possible paths this pawn could take.

This problem is not all that hard, considering that the path always takes $$2n-2$$ moves. Cancelling out the same, but reversed and tidying up the formula, we get

$$\binom{2n-2}{n-1}$$ possible paths.

Following which, the main question is what would happen if we removed some pivotal squares. Let's consider that we have a chessboard with $$n=4$$, and were to remove square $$(3,3)$$. By my logic, all we need to do is to find all the possible ways how to get to $$(4,4)$$ and to $$(3,3)$$. Then we would subtract all the ways to $$(3,3)$$ from the number of paths to $$(4,4)$$, which would give us

$$\binom{2*4-2}{4-1} - \binom{2*3-2}{3-1} =$$ $$\binom{6}{3} - \binom{4}{2} =$$ $$20 - 6 = 12$$

As I found out, this is not the correct solution. I mapped out all the possible paths, and found only $$8$$ of them. If we multiply the number of paths to $$(3,3)$$ by $$2$$, that would give us the correct solution; $$\binom{2*4-2}{4-1} - 2* \binom{2*3-2}{3-1} =$$ $$20 - 2*6 = 8$$

That begs the question, is the second solution correct? And if so, why? That, I do not know.

Additionally, what would happen if we were to remove more than one square? For example, let $$n=13$$ and lets remove two squares, $$(5,5)$$ and $$(8,8)$$. Would that be something like

$$\binom{2*13-2}{13-1} - 2* {\left[\binom{2*8-2}{8-1} + \binom{2*5-2}{5-1}\right]}$$

or did I get the whole concept wrong? Why is there that seemingly random multiplication, and how would it stack with more and more pivotal squares removed?

• But you know... pawns can only move forward... and occasionally attack diagnally... until they become something else. Dec 2, 2019 at 21:58

The paths to $$(4,4)$$ that use $$(3,3)$$ aren't just paths to $$(3,3)$$; their paths to $$(3,3)$$ and then on to $$(4,4)$$. So to count them, you need to multiply the number of ways to get from $$(1,1)$$ to $$(3,3)$$, which you calculated, with the number of ways to get from $$(3,3)$$ to $$(4,4)$$. That's $$\binom21=2$$, and this is where the missing factor $$2$$ comes from.
If you remove more than one square, you need to use inclusion–exclusion. For each subset of the removed squares, you need to add or subtract the number of paths that use that subset of removed squares, according as it contains an even or odd number of removed squares. (That number will be zero unless the orders of the $$x$$ and $$y$$ coordinates of the squares coincide.)
For instance, if you remove the squares $$(2,2)$$ and $$(3,3)$$, you're left with $$4$$ paths, and this can be calculated as follows, with $$N(S)$$ denoting the number of paths that use all squares in $$S$$:
$$\begin{eqnarray*} &&N(\emptyset)-N(\{(2,2)\})-N(\{(3,3)\})+N(\{(2,2),(3,3)\})\\ &=& \binom63-\binom21\binom42-\binom42\binom21+\binom21\binom21\binom21\\ &=& 20-2\cdot6-2\cdot6+2\cdot2\cdot2\\ &=& 20-12-12+8\\ &=& 4\;. \end{eqnarray*}$$
• So for the last case that would be $\binom{24}{12}-\binom84\binom{14}{7}-\binom{14}{7}\binom84+\binom84\binom84\binom84\\$, right?
• @Igor: Almost; I think some of your counts are off by $1$. The lower index is always the coordinate difference between the squares you're connecting. So if you're going from coordinate $1$ to $13$ while avoiding $5$ and $8$, that would be $$\binom{24}{12}-\binom84\binom{16}8-\binom{14}7\binom{10}5+\binom84\binom63\binom{10}5\;.$$ As a check, the indices (both upper and lower) in the factors of each term should add up to the same sum. Dec 3, 2019 at 12:05


# Is there a rational number between any two irrationals?

Suppose $i_1$ and $i_2$ are distinct irrational numbers with $i_1 < i_2$. Is it necessarily the case that there is a rational number $r$ in the interval $[i_1, i_2]$? How would you construct such a rational number?

[I posted this only so that the useful answers at Rationals and irrationals on the real number line could be merged here before that question was deleted.]

-
Yes, there is. This is known as the "density of the rationals in the reals", which says in fact that between any two reals numbers there is a rational number. –  Avi Steiner Jun 16 '13 at 2:24
–  MJD Jun 16 '13 at 2:37
So, wait... you asked the question, pointed to another question that already answers this... and then answered this question several days before asking it? TIME TRAVELER!!! –  BlueRaja - Danny Pflughoeft Jun 16 '13 at 5:25
@BlueRaja-DannyPflughoeft yeah, I thought that, then I read the [bit in brackets in the question]. –  Lucas Jun 16 '13 at 5:53

Let $x,y\in\mathbb{R}$, $x\neq y$. Without loss of generality, suppose $x<y$. Then there exists a positive $z$ such that $y-x=z$.

By Archimedes' axiom, there exists a natural number $n$ such that $$n > \dfrac{1}{z}$$ $$nz > 1$$ $$ny - nx > 1$$ So there exists an integer $m$ such that $$nx < m < ny$$ $$x < \frac{m}{n} < y$$ i.e. $m/n$ is a rational number between $x$ and $y$.

Since $x$ and $y$ can be any real numbers, in particular they can be irrationals.

-

Let $a$ and $b$ be distinct irrationals; we lose no generality to suppose $a<b$. Assume they have equal integer parts, since otherwise there is an integer between them and the question is trivial. They have infinite decimal expansions, $.a_1a_2a_3\ldots$ and $.b_1b_2b_3\ldots$. These cannot agree in every position since otherwise $a=b$. So say they agree up to the $n-1$th position and differ at the $n$th. Then $$x= \;.b_1b_2b_3\ldots b_n 0000000\ldots$$

is a rational number strictly between $a$ and $b$:

\begin{align} a &= \;.a_1a_2\ldots a_{n-1}a_n\ldots \\& <\; .a_2a_2\ldots a_{n-1}b_n000\ldots &= x \end{align}

because $a_n < b_n$, and

\begin{align} x & = \;.b_1b_2b_3\ldots b_n 0000000\ldots \\ & < \;.b_1b_2b_3\ldots b_nb_{n+1}\ldots & = b \end{align}

because not all of $b_{n+1}, b_{n+2}, \ldots$ can be zero.

For example, there is a rational number betwen $\sqrt2 = 1.4142\ldots$ and $\sqrt3 -\frac14 = 1.482\ldots$; this method produces the rational number $1.48000\ldots = \frac{37}{25}$. You can of course do the same thing in base 2; then you get $x = 1._20111000\ldots = \frac{23}{16}$, which also works.

It would also be fairly easy to produce a similar argument based on the continued fraction expansions of $a$ and $b$, but I think this is simpler.

-
Your proof contradicts itself by not allowing integers but allowing integers up to b_n. –  Daniel Margolis Jun 7 '13 at 18:32
One of us is confused, and I bet it's you. $b_n$ is not an integer. It is a decimal digit. And my proof doesn't "disallow" integers; it observes that if $a$ and $b$ have different integer parts then there is no need for a proof because there is an integer between them and the question is answered. –  MJD Jun 7 '13 at 18:33
I guess this shows that you can lead a horse to water, but you can't make him drink. –  MJD Jun 7 '13 at 18:49
@Daniel: There is no "infinite number place." Your conception of the notation "$\infty$" as a number (or occasionally a cardinality) seems to be at the root of all of your confusion. –  Cameron Buie Jun 15 '13 at 3:14
@JensSchauder If a has integer part 2 and b has integer part 3 and b is irrational, then 3 is indeed between a and b. –  Daenerys Naharis Jun 16 '13 at 5:44

We can construct one explicitly. Assume $0\lt a \lt b$. Let $n= \max(2,\lceil \frac 2{b-a}\rceil)$. Then let $m=\lceil na \rceil$ and $a \lt \frac m n \lt b$

-
@DanielMargolis: in the standard reals, there are no such. You (or the problem poser) have to specify them first and the difference will not be infinitesimal. It may be small, which makes $n$ large, but that is OK. Even if $a=\sqrt 2, b=\sqrt 2 + 10^{-100}$ this works. –  Ross Millikan Jun 8 '13 at 2:06
@DanielMargolis: Yes, it is. In fact, if you extend $\Bbb R$ with infinitesimals, it becomes incomplete. If you have an infinitesimal $\epsilon$, the set $\{\frac 1n|n \in \Bbb N\}$ has $0$ as a lower bound, but it has no greatest lower bound. –  Ross Millikan Jun 8 '13 at 13:05
If you are working in some number system that includes infinitesimals, you should say that. There is no indication in the question that you are, and all the answers to this and your other question are in the real numbers. I know very little about such systems. You seem to have an intuitive sense of how you want the infinitesimals to behave, but I don't think they can act that way. –  Ross Millikan Jun 8 '13 at 13:33
@CameronBuie: yes, he is including infinitesimals, which comes out late in this discussion, as well as another question he asks. Then he wants to lump all infinitesimals with the standard irrationals. I am not sure if it is confusion or trolling. –  Ross Millikan Jun 15 '13 at 15:55
@Daniel: Noone is claiming that irrationals have finite decimal expansions--their definitions do indeed have infinitely many decimal places. What do you mean by "an infinite decimal place," though? –  Cameron Buie Jun 16 '13 at 2:32

Be $a$ and $b$ two irrational numbers, with $a<b$. Since $a<b$, we have $b-a>0$. Now there are rational numbers arbitrary close to $0$, and therefore there's a rational number $q<b-a$. Now consider the set $M=\{qn: n\in \mathbb{Z}\}$. Now be $q_l$ the largest element of $M$ less than $a$, and $q_r$ the smallest element of $M$ greater than $b$. Clearly $q_r-q_l > b-a$. However, if there's no rational number between $a$ and $b$, then there's especially no element of $M$ between $a$ and $b$, because all elements of $M$ are rational. But then $q_r$ is the element of $M$ following $q_l$, that is, $q_r-q_l = q$. But by construction, $q<b-a$, so we have $b-a < q_l-q_r = q < b-a$ which is a contradiction. Therefore there's at least one element of $M$, which is a rational number, in between $a$ and $b$.

-
@DanielMargolis: I didn't claim it is. –  celtschk Jun 7 '13 at 23:16
The real numbers are totally ordered, that means exactly one of $a-b>0$, $a-b=0$, $a-b<0$ is true. $a-b=0$ would mean $a=b$, but by assumption, $a$ and $b$ are different (were $a=b$, quite trivially there would be no rational number between $a$ and $b$). So this leaves $a-b>0$ and $a-b<0$. I further assumed that $a$ denotes the smaller of the two, i.e. $a<b$, which is equivalent to $b-a>0$. So $b-a>0$ by the initial assumption (but that's just a wlog assumption; if we had $a<b$, you could just use $a-b$ instead). –  celtschk Jun 8 '13 at 8:39
@DanielMargolis: There cannot be such an $R$ because all sequences of rational numbers whose absolute value eventually stays beyond any given rational number converge to $0$. So any number that is closer to $0$ than any rational number cannot be the limit of a sequence of rational numbers, in contradiction to $\mathbb{R}$ being the completion of $\mathbb{Q}$. –  celtschk Jun 8 '13 at 9:19
$1/n*irr$ is not an irrational number, it is a whole sequence of irrational numbers. And not a single one is closer to $0$ than all rational numbers. Yes, for every rational number (with the exception of $0$ itself, of course), there's an irrational number that's closer to $0$. But there's no irrational number which is closer to $0$ than every rational number, because for each irrational number there's a rational number which is even closer to $0$. –  celtschk Jun 8 '13 at 10:13
Do you really not know the difference between "thhere is no irraltional number closer to $0$ than any rational number" (true) and "for any rational number there is no irrational number closer to it" (false)? In that case, do yourself a favour and learn elementary logic. –  celtschk Jun 8 '13 at 11:17

## protected by Asaf KaragilaJan 15 '14 at 21:21

Thank you for your interest in this question. Because it has attracted low-quality answers, posting an answer now requires 10 reputation on this site.


# Probability of drawing an ace or 2 after an ace - intuition

This question is a follow-up question on this one: Probability of drawing an ace or 2 after an ace

Background Out of a standard deck you draw cards (without replacement) one by one until you reach an ace. Then you continue to draw cards until you reach another ace or a "2" card. What is the probability that you reached a "2" card and not an ace?

The solution To shorten things up, let's assume the deck has only two aces and two "2" cards. Clearly, all that matters are the relative position of these two cards, not all the other cards. So we can think of the permutations of 4 items in a row.

The event "the card following the first ace is ace" occurs when the two aces are together. The sample space is $${4 \choose 2}$$ (choosing 2 places for the aces) and there are 3 locations in which they are together (1-2,2-3,3-4) so the solution is $$\tfrac{3}{{4\choose 2}}=0.5$$.

Surprisingly, the answer $$0.5$$ remains correct even if there are 4 aces and 4 "2"s in the original deck and in fact, as @InterstellarProbe shows in the comments to the original question, if there are $$n+1$$ of each type, the answer is: $$\sum_{k=0}^{n+1} \frac{n\left(\begin{array}{c} n+k \\ k \end{array}\right)}{(n+k)\left(\begin{array}{c} 2 n+2 \\ n+1 \end{array}\right)}=\frac{1}{2}$$

The question The above result surprises me a bit. There is no obvious symmetry in the question and it is not obviously clear why there is the same number of arrangements in which after the first ace comes another one as arrangements in which after the first ace comes a "2". I spent a couple of months thinking, asked also fellow probability teachers, but no-one had a good idea.

So, returning the ball to this court. What is the intuitive explanation to this result? Why the permutations are symmetric and how can we get this $$\tfrac{1}{2}$$ without the algebra?

• I would say that it looks asymmetric because you don't think about what happens before that first ace. You might have already discarded several 2's. – Marc Romaní Nov 24 '20 at 14:32

I'm not sure that the following solution is any more intuitive than others (in my experience, some probability problems are simply non-intuitive, at least with my intuition), but at least it is a different approach than those given so far.

To start with, we can ignore all the cards in the deck except for aces and twos. So suppose we have a deck of four aces and four twos, which can be arranged in $$8!$$ ways, all of which we assume are equally likely. We want to find the probability that the card following the first ace in the deck is also an ace.

As a further simplification, let's see if we can find the probability that the card immediately following the first ace is the ace of spades. We want to count the number of such arrangements. To do so, suppose we remove the ace of spades from the deck and deal out the remaining cards; this can be done in $$7!$$ ways. There is only one place where the ace of spades can now go so that it is immediately following the first ace, so the number of arrangements in which the ace of spades follows the first ace is $$7!$$, and the probability of this event is $$\frac{7!}{8!} = \frac{1}{8}$$

If we don't care which ace follows the first ace in the deck, there are $$4$$ possible choices, all of which have the same probability of $$1/8$$. So the probability that the card following the first ace is also an ace is $$4 \cdot \frac{1}{8} = \frac{1}{2}$$

• It wasn't what I was looking for (searched for symmetry of the permutations) but this is an excellent answer. Following on that logic, from symmetry, the probability of any card to be after the first ace is equal so it must be $\tfrac{1}{8}$ and the probability that it would be an ace is $0.5$. The generalization to more cards and more types (ace, 2, and kings...) is straightforward. Great! – YJT Nov 24 '20 at 17:46


# Equation of locus of points satisfied by $\frac{\left|z+3i\right|}{\left|z-6i\right|}=1$

Equation of locus of points satisfied by $\frac{\left|z+3i\right|}{\left|z-6i\right|}=1$

The answer I got is $y=\frac{3}{2}$, but the answer given in my book is $y=-0.5x+2.25$

Can anyone please confirm which is the right answer

Edit: Sorry, the modulus was on each numerator and denominator, not for the whole thing, though I don't think this makes a difference.

My working

subbing $z=x+yi$ gives

$\frac{\left|x+yi+3i\right|}{\left|x+yi-6i\right|}=1$

$\frac{x^2+(y+3)^2}{x^2+(y-6)^2}=1^2$

Expanding brackets and then solving gives

$y=3/2$

Thank You

• Please show us your workings, i.e. your work from which you "got is $y=\frac 32$. Other wise, we cannot confirm your solution. So, show us how you arrived at your answer, by editing your post to include it. – Namaste Aug 22 '17 at 20:11
• I think you're right. The equation says point $z$ is equidistant from $-3i$ and $6i$, which should be a horizontal line at $y=1.5$. – Jirapat Samranvedhya Aug 22 '17 at 20:12
• @amWhy I have done so now. Thanks – NumberCruncher Aug 22 '17 at 20:22
• @JirapatSamranvedhya Thanks very much, that's how I thought about it first too. – NumberCruncher Aug 22 '17 at 20:22
• NumberCruncher Thank you for including your work! – Namaste Aug 22 '17 at 22:10

To cut down on unanswered questions, here we go!

The book's answer is certainly wrong, as one readily sees by considering $z=\frac94i.$

Now, we clearly cannot have $z=6i$ as a solution, for then we have $\frac90=1,$ which is nonsensical. Consequently, the given equation is equivalent to $$|z+3i|=|z-6i|,$$ or, put another way, to $$\bigl|z-(-3i)\bigr|=|z-6i|.$$

Since $|z-w|$ is the distance from $z$ to $w$ for all $z,w\in\Bbb C,$ then the equation above says that $z$ is equidistant from $-3i$ and $6i.$ Readily, putting $z=x+iy,$ this is equivalent to saying that $(x,y)$ is equidistant from $(0,-3)$ and $(0,6),$ i.e.: $$\sqrt{x^2+(y+3)^2}=\sqrt{x^2+(y-6)^2}.$$ This is, of course, equivalent to your approach, and solving the preceding equation yields $y=\frac32,$ as you say.

Given two points, the set of points equidistant from them is the perpendicular bisector of the line joining them.

If the points are $(a, b)$ and $(c,d)$, the midpoint is $((a+c)/2, (b+d)/2)$.

The slope of the line is $\dfrac{d-b}{c-a}$, so the slope of the normal is the negative reciprocal of this or $-\dfrac{c-a}{d-b} =\dfrac{a-c}{d-b}$.

Therefore the equation of the perpendicular bisector is $\dfrac{y-(b+d)/2)}{x-(a+c)/2} =\dfrac{a-c}{d-b}$.

If $a=c=0$, as in this case, the equation is $\dfrac{y-(b+d)/2)}{x} =0$ or $y=(b+d)/2$.

In this case, $b=-3$ and $d=6$, so the equation is $y =(6-3)/2 =3/2$.