37  Integrals step-by-step

The setting for anti-differentiation (and its close cousin, integration) is that we have a function \(F(t)\) which we do not yet know, but we do have access to some information about it: its slope as a function of time \(f(t) \equiv \partial_t F(t)\) and, perhaps, its value \(F(t_0)\) at some definite input value.

Chapter 35 showed some ways to visualize the construction of an \(F(t)\) by accumulating short segments of slope. The idea is that we know \(f(t)\) which tells us, at any instant, the slope of \(F(t)\). So, in drawing a graph of \(F(t)\), we put our pen to paper at some input value \(t_0\) and then move forward in \(t\), setting the instantaneous slope of our curve according to \(f(t)\).

In Chapter 36, we dealt with one of the limitations of finding \(F(t)\) by anti-differentiation of \(f(t)\); the anti-derivative is not unique. This is because to start drawing \(F(t)\) we need pick a \(t_0\) and an initial value of \(F(t_0)\). If we had picked a a different starting point \(t_1\) or a different initial value \(F(t_1)\), the new curve would be different than the one drawn through \((t_0, F(t_0))\), although it would have the same shape, just shifted up or down according to our choice. We summarize this situation algebraically by writing \[\int f(t) dt = F(t) + C\ ,\] where \(C\) is the constant of integration, that is, the vertical shift of the curve.

The non-uniqueness of \(F(t)\) does not invalidate its usefulness. In particular, the quantity \(F(b) - F(a)\), will be the same regardless of which starting point we used to draw \(F(t)\). We have two names for \(F(b) - F(a)\)

  1. The net change in \(F()\) from \(a\) to \(b\).
  2. The definite integral of \(f()\) from \(a\) to \(b\), written \(\int_a^b f(t) dt\).

These two things, the net change and the definite integral, are really one and the same, a fact we describe by writing \[\int_a^b f(t) dt = F(b) - F(a)\ .\]

In this chapter, we will introduce a simple numerical method for calculating from \(f()\) the net change/definite integral. This will be a matter of trivial but tedious arithmetic: adding up lots of little bits of \(f(t)\). Later, in Chapter Chapter 38, we will see how to avoid the tedious arithmetic by use of algebraic, symbolic transformations. This symbolic approach has great advantages, and is the dominant method of anti-differentiation found in college-level science textbooks. However, there are many common \(f(t)\) for which the symbolic approach is not possible, whereas the numerical method works for any \(f(t)\). Even more important, the numerical technique has a simple natural extension to some commonly encountered accumulation problems that look superficially like they can be solved by anti-differentiation but rarely can be in practice. We will meet one such problem and solve it numerically, but a broad approach to the topic, called dynamics or differential equations, will have to wait until Block 6.

37.1 Euler method

The starting point for this method is the definition of the derivative of \(F(t)\). Reaching back to Chapter 8,

\[\partial_t F(t) \equiv \lim_{h\rightarrow 0} \frac{F(t+h) - F(t)}{h}\]

To translate this into a numerical method for computing \(F(t)\), let’s write things a little differently.

  • First, since the problem setting is that we don’t (yet) know \(F(t)\), let’s refer to things we do know. In particular, we know \(f(t) = \partial_t F(t)\).
  • Again, recognizing that we don’t yet know \(F(t)\), let’s re-write the expression using something that we do know: \(F(t_0)\). Stated more precisely, \(F(t_0)\) is something we get to make up to suit our convenience. (A common choice is \(F(t_0)=0\).)
  • Let’s replace the symbol \(h\) with the symbol \(dt\). Both of them mean “a little bit of” and \(dt\) makes explicit that we mean “a little bit of \(t\).”
  • we will substitute the limit \(\lim_{h\rightarrow 0}\) with an understanding that \(dt\) will be something “small.” How small? we will deal with that question when we have to tools to answer it.

With these changes, we have \[f(t_0) = \frac{F(t_0+dt) - F(t_0)}{dt}\ .\] The one quantity in this relationship that we do not yet know is \(F(t_0 + dt)\). So re-arrange the equation so that we can calculate the unknown in terms of the known. \[F(t_0 + dt) = F(t_0) + f(t_0)\, dt\ .\]

Let’s consider finding the anti-derivative of \(\dnorm()\), that is, \(\int_0^t \dnorm(x) dx\). In one sense, you already know the answer, since \(\partial_x \pnorm(x) = \dnorm(x)\). In reality, however, we know \(\pnorm()\) only because it has been numerically constructed by integrating \(\dnorm()\). The \(\pnorm()\) function is so important that the numerically constructed answer has been memorized by software.

37.2 Area

The quantity \[\Large \color{magenta}{f(t_0)}\, \color{orange}{dt}\] gives rise to a visualization that has been learned by generations of calculus students. The visualization is so compelling and powerful that many students (and teachers, and textbook authors) mistake the visualization for integration and anti-differentiation themselves.

We will start the visualization with a simple graph of \(f(t)\), which is called the integrand in the integral \(\int_a^b f(t) dt\). Figure 37.1 shows the graph of \(f(t)\). A specific point \(t_0\) has been marked on the horizontal axis. Next to it is another mark at \(t_0 + dt\). Of course, the distance between these marks is \(\color{orange}{dt}\).

Figure 37.1: Illustrating the interpretation of \(f(t_0) dt\) as an “area”.

Per the usual graphical convention, a position along the vertical axis corresponds to a possible output of \(f(t)\). The output for \(t=t_0\) is \(\color{magenta}{f(t_0)}\). That same quantity corresponds to the length of the vertical orange segment connecting \((t_0, 0)\) to \((t_0, f(t_0))\).

The \(\color{orange}{dt}\) line segment and the \(\color{magenta}{f(t_0)}\) segment constitute two sides of a rectangle, shown as a shaded zone. The “area” of that rectangle is the product \(\color{magenta}{f(t_0)}\ \color{orange}{dt}\).

In this sort of visualization, an integral is the accumulation of many of these \(f(t) dt\) rectangles. For instance, Figure 37.2 the visualization of the integral \[\int_{0}^3 f(t) dt\ .\]

## Warning in is.na(x): is.na() applied to non-(list or vector) of type
## 'expression'

## Warning in is.na(x): is.na() applied to non-(list or vector) of type
## 'expression'

## Warning in is.na(x): is.na() applied to non-(list or vector) of type
## 'expression'

Figure 37.2: Visualizing the integral \(\int_0^3 f(t) dt\) as the total “area” of several \(f(t) dt\) bars. The width of each of the bars is \(dt\). The height depends on the value of the function \(f(t)\) at the bar. For illustration, two of the bars are marked with vertical and horizontal line segments.

As always in calculus, we imagine \(dt\) as a “small” quantity. In ?fig-bars-0-3B you can see that the function output changes substantially over the sub-domain spanned by a single rectangle. Using smaller and smaller \(dt\), as in ?fig-bars-0-3-small brings the visualization closer and closer to the actual meaning of an anti-derivative.

Visualizing the integral \(\int_0^3 f(t) dt\) as the total “area” of several \(f(t) dt\) bars. The width of each of the bars is \(dt\). The height depends on the value of the function \(f(t)\) at the bar. For illustration, two of the bars are marked with vertical and horizontal line segments.

Why do you keep putting “area” in quotes?

When \(f(t_i) < 0\), then \(f(t_i) dt\) will be negative. There is no such thing as a negative area, but in constructing an integral the \(f(t_i)dt\), being negative, diminishes the accumulated area.

Figure 37.3: The \(\int_{-2}^3 g(t) dt\) covers subdomains where \(g(t) > 0\) and where \(g(t) < 0\). In those latter subdomains, the “area” is negative, and shown in light orange here.

Another problem is that area is a physical quantity, with dimension L\(^2\). The quantity produced by integration will have physical dimension \([f(t)][t]\), the product of the dimension of the with-respect-to quantity and the output of the function.

“Area” is an effective metaphor for visualizing integration, but the goal of integration is not to calculate an area but, typically, some other kind of quantity.

37.3 The Euler Step

The previous section a visualization of an integral in terms of an area on a graph. As you know, a definite integral \(\int_a^b f(t) dt\) can also be computed by constructing the anti-derivative \(F(t) \equiv \int f(t) dt\) and evaluating it at the upper and lower bounds of integration: \(F(b) - F(a)\). In this section, we will look at the numerical process of constructing an anti-derivative function, which uses many of the same concepts as those involved in finding an integral by combining areas of rectangles.

A definite integral produces a quantity, not a function. The anti-derivative function constructed by using quantities like \(f(t) dt\) will be a series of quantities rather than a formula. In particular, it will have the form of a data table, something like this:

\(t\) \(F(t)\)
-2 10.62
-1.5 6.47
-1 3.51
-0.5 2.02
0 2.4
0.5 3.18
1.0 5.14
\(\vdots\) \(\vdots\)

To start, we will need to create a series of \(t\) values. We will do this by specifying a starting value for \(t\) and then creating successive values by adding a numerical increment \(dt\) to the entries one after the other until we reach a terminating value. For instance, in the above table, the starting value for \(t\) is \(-2\), the numerical increment is \(dt=0.5\), and the terminating value is \(1\).

In previous chapters of this book we have worked with data tables, but always the data table was given to us, we did not have to construct it.1 Now we need to construct the data frame with the \(t\) column containing appropriate values. Computer languages provide many ways to accomplish this task. We will use a simple R/mosaic function Picket(), which constructs a data table like the one shown above. You provide two arguments: the domain for \(t\), that is, the desired upper and lower bounds of integration; the interval size \(dt\) (which is called h in the argument list). For instance, to construct the \(t\) column of the table shown above, you can use Picket() this way:

Pts <- Picket(bounds(t = -2:1), h=0.5)
Pts
## # A tibble: 6 × 3
##       t preweight weight
##   <dbl>     <dbl>  <dbl>
## 1  -2           1    0.5
## 2  -1.5         1    0.5
## 3  -1           1    0.5
## 4  -0.5         1    0.5
## 5   0           1    0.5
## 6   0.5         1    0.5

As you can see, the data table produced by Picket() has the \(t\) column, as well as a second column named weight. We haven’t explained weight yet, but you can see that it is the same value we specified as h.

The name Picket() is motivated by the shape of a picket fence. The pickets are evenly spaced, which keeps things simple but is not a requirement.

Note that the picket does not say anything at all about the function \(f(t)\) being anti-differentiated. The picket can be applied to any function although precision might require a smaller \(dt\) for functions that have a lot going on in a small domain.

The next step in using the picket to perform anti-differentiation is to apply the function \(f()\) to the pickets. That is, we will add a new column, perhaps called vals to the data table.

Adding a new column is a common task when dealing with data. We will do this with a new function, mutate(), whose specific function is adding new columns (or modifying old ones). Here’s the command to apply \(f()\) to t and call the new column vals:

# Find the height of the pickets
Pts <- Pts %>%
  mutate(vals = f(t))

With this modification, the data table looks like:

## # A tibble: 6 × 4
##       t preweight weight  vals
##   <dbl>     <dbl>  <dbl> <dbl>
## 1  -2           1    0.5 -9.12
## 2  -1.5         1    0.5 -7.27
## 3  -1           1    0.5 -4.50
## 4  -0.5         1    0.5 -1.46
## 5   0           1    0.5  1.28
## 6   0.5         1    0.5  3.31

Now that we know the value of the function at each of the pickets, the next step is to multiply the value by the spacing between pickets. That spacing, which we set with the argument h = 0.5 in our original call to Picket() is in the column called weight. we will call the result of the multiplication step. Note that the following R command incorporates the previous calculation of vals; we are looking to build up a single command that will do all the work.

# Multiply the height by the picket spacing
Pts <- Pts %>%
  mutate(vals = f(t),
         step = vals * weight)
Pts
## # A tibble: 6 × 5
##       t preweight weight  vals   step
##   <dbl>     <dbl>  <dbl> <dbl>  <dbl>
## 1  -2           1    0.5 -9.12 -4.56 
## 2  -1.5         1    0.5 -7.27 -3.63 
## 3  -1           1    0.5 -4.50 -2.25 
## 4  -0.5         1    0.5 -1.46 -0.732
## 5   0           1    0.5  1.28  0.639
## 6   0.5         1    0.5  3.31  1.66

We used the name step to identify the product of the height and spacing of the pickets to help you think about the overall calculation as accumulating a series of steps. Each step provides a little more information about the anti-derivative that we will now calculate. In terms of the area metaphor for integration, each step is the area of one vertical bar of the sort presented in the previous section.

We will call these Euler steps, a term that will be especially appropriate when, in Block 6, we use integration to calculate the trajectories of systems—such as a ball in flight—that change in time.

The final step in constructing the anti-derivative is to add up the steps. This is simple addition. But we will arrange the addition one step at a time. That is, for the second row, the result will be the sum of the first two steps. For the third row, the result will be the sum of the first three steps. And so on. The name for this sort of accumulation of the previous steps is called a cumulative sum. Another name for a cumulative sum is a “running sum”: the sum-so-far as we move down the column of steps. Cumulative sums are computed in R by using cumsum(). Here, we are calling the result of the cumulative sum F to emphasize that it is the result of anti-differentiating \(f()\). But keep in mind that the anti-derivative is not just the F column, but the table with both t and F columns. That is, the table has a column for the input as well as the output. That is what it takes to be a function.

# Doing everything in one command
Pts <- 
  Picket(bounds(t = -2:1), h=0.5) %>%
  mutate(vals = f(t),
         step = vals * weight,
         F = cumsum(step))
## # A tibble: 6 × 6
##       t preweight weight  vals   step      F
##   <dbl>     <dbl>  <dbl> <dbl>  <dbl>  <dbl>
## 1  -2           1    0.5 -9.12 -4.56   -4.56
## 2  -1.5         1    0.5 -7.27 -3.63   -8.19
## 3  -1           1    0.5 -4.50 -2.25  -10.4 
## 4  -0.5         1    0.5 -1.46 -0.732 -11.2 
## 5   0           1    0.5  1.28  0.639 -10.5 
## 6   0.5         1    0.5  3.31  1.66   -8.88

We can summarize the steps in this Euler approach to numerical integration graphically:

{#fig-euler-integration1, fig-align=‘center’ width=90%}

Figure 37.4: Steps in a numerical construction of an anti-derivative. (1) Create a set of picket locations over the domain of interest. The locations are spread horizontally by amount dt, so each picket will be dt units wide. (2) evaluate the original function at the picket points to give picket heights. (3) Multiply the picket height by the picket width to create an “area”. (4) Starting at zero for the left-most picket, add in successive picket areas to construct the points on the anti-derivative function (green). Note that the vertical axis in (4) has a different dimension and units than in steps (1)-(3). In (4) the vertical scale is in the units of the anti-derivative function output.

Figure 37.5 shows a dynamic version of the process of constructing an anti-derivative by Euler steps. The integrand \(f(t)\) is shown in the top panel, the anti-derivative \(F(t)\) is shown being built up in the bottom panel. The \(\color{magenta}{\text{magenta}}\) bar in the top plot is the current Euler step. That step is added to the previously accumulated steps to construct \(F(t)\).

PROVIDE LINK TO MOVIE IN PDF version.

Figure 37.5: A dynamic view of building \(F(t)\) from \(f(t)\) by accumulating Euler steps.

Math in the World: Russian COVID-19 cases

The following graphic from a well-respected news magazine, The Economist, shows the reported number of cases and deaths from Covid-19 during a two-year period in Russia. (“Sputnik” is the name given to a Russian-developed vaccine, named after the first man-made satellite in Earth orbit, launched by the Soviet Union on Oct. 4, 1957 and precipitating a Cold-War crisis of confidence in in the US.)

Figure 37.6: COVID in Russia. (Source: The Economist)

The figure caption gives information about the units of the quantities being graphed. Notice the word “daily,” which tells us, for example, that in mid-2021 there were about 10,000 new cases of Covid-19 each day and correspondingly about 350 daily deaths.

How many total cases and total deaths are reported in the graphic?

There are, of course, two distinct ways to present such data which can be easily confused by the casual reader. One important way to present data is as cumulative cases and deaths as a function of date. We will call these \(C(t)\) and \(D(t)\). Another prefectly legitimate presentation is of the rate of change \(\partial_t C(t)\) and \(\partial_t D(t)\) which, following our informal capital/lower-case-letter convention, we could write \(c(t)\) and \(d(t)\). Since there is no such thing as a “negative” case or death, we know that \(C(t)\) and \(D(t)\) are monotonic functions, never decreasing. So the graphs cannot possibly be of \(C(t)\) and \(D(t)\), since the graphs are far from monotonic. Consequently, the displayed graphs are \(c(t)\) and \(d(t)\), as confirmed by the word “daily” in the caption.

To find \(C(t)\) and \(D(t)\) requires integrating \(c(t)\) and \(d(t)\). The value of \(C(t)\) and \(D(t)\) at the right-most extreme of the graph can be found by calculating the “area” under the \(c(t)\) and \(d(t)\) curves. But care needs to be taken in reading the horizontal axis. Although the axes are labelled with the year, the tick marks are spaced by one month. (Notice “month” does not appear in the caption.) The far right end of the graph is in early July 2021. The far left end, when the graph moves away from zero cases and deaths, is early April 2020.

You can do a reasonable job estimating the “area” by extending the tick marks on the horizontal axis and counting the resulting rectangles that fall under the curve.

Figure 37.7: Dividing the domain into regions of width \(dt = 1\) month.

For the graph of cases, the “area” of each rectangle is \(\frac{5000\, \text{cases}}{\text{ day}}\cdot \text{1 month}\). This has the right dimension, “cases,” but the units are screwy. So replace 1 month with 30.5 days (or thereabouts) to get an “area” of each rectangle of 172,500 cases. Similarly, the “area” of the rectangles on the right graph is 3050 deaths.

37.4 Better numerics (optional)

Except as a textbook exercise, you will likely never have to compute a numerical anti-derivative from scratch as we did in the previous section. This is a good thing. To understand why, you have to know one of the important features of modern technical work. That feature is: We never work alone in technical matters. There is always a set of people whose previous work we are building on, even if we never know the names of those people. This is because technology is complicated and it is evidently beyond the reach of any human to master all the salient aspects of each piece of technology being incorporated into the work we consider our own.

Of course this is true for computers, since no individual can build a useful computer from first principles. It is also true for software. One detail in particular is relevant to us here. Computer arithmetic of the sort used in the previous section—particularly addition—is prone to error when adding up lots and lots of small bits. This means that it is not always sensible to choose very small \(dt\) to get a very accurate approximation to the anti-derivative.

Fortunately, there are specialists in numerical mathematics who work on ways to improve the accuracy of calculations for mid-sized \(dt\). Their work has been incorporated into the results of antiD() and Integrate() and so the details are, for us, unimportant. But they are only unimportant because they have been taken care of.

To illustrate how considerably more accuracy can be gained in calculating an anti-derivative, consider that the rectangular bars drawn in the previous sections are intended to approximate the “area” under the function. With this in mind, we can replace the rectangular bars with more suitable shapes that stay closer to the function over the finite extend of each \(dt\) domain. The rectangular bars model the function as piecewise constant. A better job can be done with piecewise linear approximations or piecewise quadratic approximations. Often, such refinements can be implemented merely by changing the weight column in the picket data frame used to start off the process.

One widely used method, called Gauss-Legendre quadrature can calculate a large segment of an integral accurately (under conditions that are common in practice) with just five evaluations of the integrand \(f(t)\).

Picket locations and weights For the integral \(\int_a^b f(t) dt\) where \(c = \frac{a+b}{2}\) and \(w = (b-a)/2\).

location weight
\(c - 0.90618 w\) \(0.236927 \times w\)
\(c - 0.53847 w\) \(0.478629 \times w\)
\(c\) \(0.568889 \times w\)
\(c + 0.53847 w\) \(0.478629 \times w\)
\(c + 0.90618 w\) \(0.236927 \times w\)

The locations and weights may seem like a wizard parody of mathematics, but those precise values are founded in an advanced formulation of polynomials rooted in the theory of linear combinations to which you will be introduced in Block 5. Needless to say, you can hardly be expected to have any idea where they come from. That is why it is useful to build on the work of experts in specialized areas. It is particularly helpful when such expertise is incorporated into software that faithfully and reliably implements the methods. The lesson to take to heart: Use professional software systems that have been extensively vetted.

37.5 Exercises

Exercise 37.01

The output of a function, being a quantity, has dimension and units. Suppose the dimension of the output of a function \(v(t)\) is \(L/T\), for instance, meters-per-second.

The anti-derivative function \(V(t) \equiv \int v(t) dt\) will also have dimension and units.

Recall that in constructing the anti-derivative using the Euler method, we multiply the values of \(v(t)\) times some small increment in the input, \(h\). Therefore the dimension of the output of \(V(t)\) will be \([v(t)] [t]\). So if \([v(t)] = L/T\), the dimension \([V(t)] [t] = L T/T = L\). Units for such a dimension would be, for instance, meters. This makes sense, since if you accumulate velocity (meters-per-sec) over an interval of time (sec) you end up with the distance travelled (meters).

Suppose you know the acceleration \(a(t)\) of an object as a function of time. The dimension of acceleration is \(L/T^2\).

Part A What is the dimension of \[\int a(t) dt\ \text{?}\]

\(L/T^3\)\(L\)\(LT\)\(L/T\)\(LT^2\)

Suppose you know the power consumed by an appliance \(p(t)\) as a function of time. Typically appliances have a cycle and use different amounts of power during different parts of the cycle. (Think of a clothes washer.)

Part B What will be the dimension of \(\int p(t) dt\ \text{?}\)

energy force acceleration length

Exercise 37.02

This activity uses the “Graph-antiD” web app which enables you to visualize the anti-derivative function in terms of areas. To use the app, click-drag-and-release to mark part of the domain of the function being displayed.

Add a picture of the app and a link to it.

To answer these questions correctly, you must set the “Shape of function” box to 864.

Part A A. From the graph, roughly estimate \[\int_0^3 f(t)dt\] Choose the closest numerical value from the following. You could use either graph for this caclulation, but \(F(t)\) will be simpler algebra.

-46 -26 0 3 19 26

Part B B. to construct the anti-derivative whose value at time \(t=-3\) will be zero, what constant of integration \(C\) should you add to the \(F(t)\) shown.

-120 -80 -50 0 50 80 120

Part C C. Examining the stock at time \(t=0\), you observe that there are 40 units. Roughly how much stock will there be at \(t=5\)?

-25 -15 0 15 25

Part D D. You start with a stock of 100 units at time \(t = -2\). At roughly what time \(t\) will the stock be half of this?

  1. -1.2
  2. -0.3
  3. 0.5
  4. 1.2
  5. 1.8
  6. The stock will never fall so low.

Part E E. Your stock finally runs out at time \(t=2.5\). When did you have 120 units in stock?

  1. \(t=-4\)
  2. \(t=-3\)
  3. \(t=0\)
  4. There was never such a time.

Part F F. After decreasing for a long time, the stock finally starts to increase from about \(t=2.5\) onward. What about \(f(t=2.5)\) tells you that \(F(t=2.5)\) is increasing?

  1. The derivative is at a minimum.
  2. The derivative is negative
  3. The derivative is near zero.
  4. The derivative becomes positive and stays positive.
  5. The derivative is at a maximum.

Part G G. Find the argmin \(t^\star\) of \(f(t)\) and note the sign of \(f(t^\star).\) What does this tell you about \(F(t^\star)\).

  1. \(t^\star\) is also the argmin of \(F()\).
  2. \(F(t^\star)\) is decreasing at its steepest rate.
  3. \(F(t^\star)\) is increasing at its slowest rate.
  4. \(F(t^\star)\) is increasing at its steepest rate.
  5. \(t^\star\) is the argmax of \(F()\)

Part H H. What is the average flow into stock over the period \(-5 \leq t \leq 1\). (If the flow is outward from stock, that is the same as a negative inward flow.)

-30 -20 0 10

Part I I. Which of the following is an interval when the average flow is approximately zero?

  1. \(-1.3 \leq t \leq 1.1\)
  2. \(0.8 \leq t \leq 5\)
  3. \(-5 \leq t \leq 0\)
  4. None of the above

Part J J. From the graph, estimate \[\int_2^{-4} f(t)dt\] Choose the closest numerical value from the following.

  1. -120
  2. -60
  3. 60
  4. 120
  5. None of these answers are close to being right.

Exercise 37.03

Consider this function, \(f(t)\):

Assume that the “area” of each small box on the graph is the product of 1 Watt \(\times\) 1 second.

Part A What is \[\int_1^2 f(t) dt\ \text{?}\] (Choose the closest answer. The units are in Watt-seconds.)

-3.2 -1.4 0 2.5 3.3 6.1

\[\text{Let}\ \ A = \int_1^3 f(x) dx\ \ \ \text{and}\ \ \ B = \int_2^4 f(x) dx\]

Part B Which is bigger, A or B?

  1. A
  2. B
  3. They are the same size

\[\text{Let}\ \ A = \int_3^1 f(t) dt\ \ \ \text{and}\ \ \ B = \int_4^2 f(t) dt\]

Part C Which is bigger, A or B?

  1. A
  2. B
  3. They are the same size

Consider the function \[g(x) \equiv \int_4^x f(t) dt\] for the next three questions

Part D Which is bigger, \(g(8)\) or \(g(9)\)?

  1. \(g(8)\)
  2. \(g(9)\)
  3. They are the same size
  4. Trick question! There can be no such function \(g(x)\) since \(f()\) is a function of \(t\)

Part E Is \(g(2.5)\) positive or negative?

positive zero negative

Part F At what value of \(x\) is \(g(x) = 0\)?

2 3 4 5 6 7 8

\[\text{Let}\ \ h(x) \equiv \int_0^x f(t) dt\]

Part G At what value of \(x\) is \(h(x) \approx 0\)?

1 2 3 4 5 6

\(\partial_x h(x)\) is a function. When we write \(\partial_x h(3)\) we mean to evaluate that function for an input value of \(x=3\).

Part H Which is bigger, \(\partial_x h(3)\) or \(\partial_x h(4)\)?

\(\partial_x h(3)\)\(\partial_x h(4)\) Can’t tell.

\[\text{Let}\ \ y(x) \equiv \int_4^x f(t) dt\]

Here are four different graphs.

slice_plot(F(x) - F(4) ~ x, bounds(x=0:10)) %>%
  gf_labs(title = "(A)")

slice_plot(F(4) - F(x) ~ x, bounds(x=0:10)) %>%
  gf_labs(title = "(B)")

slice_plot(F(6) - F(x) ~ x, bounds(x=0:10)) %>%
  gf_labs(title = "(C)")

slice_plot(abs(F(4) - F(x)) ~ x, bounds(x=0:10)) %>%
  gf_labs(title = "(D)")

Part I Which of the graphs shows \(y(x)\)?

A B C D

Exercise 37.04

Using the Euler method find \(\int f(t) dt\) over the interval \(t_0=0\) to \(t_{end}=1\). The \(t\) quantity is in steps of \(h=0.01\).

\(t\) \(\partial_t f(t)\) \(\int f(t) dt\)
0 0.399 0.5
0.01 0.242
0.02 0.054
0.03 0.399

Exercise 37.05

Consider this sequence: 4, 5, 3, 1, 2

Part A What is the sum?

14 15 16 17

Part B What is the cumulative sum?

  1. The sequence 4, 9, 12, 13, 15
  2. The sequence 2, 3, 6, 11, 15
  3. The sequence 0, 4, 9, 13, 15

Part C Which entry in the cumulative sum matches the sum?

The first The last None of them All of them

Exercise 37.06

The result of applying the Euler method to a function is also another function, but it comes in the form of a vector of numbers all ready to be displayed graphically. So keep in mind the the function produced by Euler will be known only over a specified domain, just as the graph of a function covers only the specified domain. For instance, here is the graph of the natural logarithm function over the domain \(1 \leq x \leq 21\).

slice_plot(log(x) ~ x, bounds(x=1:21), npts=11) %>%
  gf_point()

The command in the sandbox is a little different than the usual slice_plot(). We’ve added on two things:

  1. An argument npts=11 which says to use 11 discrete values of the input in plotting the graph.

  2. A second graphics layer that shows a dot at each input point where slice_plot() evaluated the function. Behind the seemingly smooth curves that slice_plot() produces is really a discrete set of points each of which is the output of the function at some numerical input.

In our typical use of slice_plot() we leave out the dots and show only the straight line segments that connect the positions where the dots would be plotted. If the positions are spaced closely enough, your eye will not see the joints between successive straight lines and you will perceive the graph as a smooth curve.

Part A For the graph of the log function over the domain \(1 \leq x \leq 21\) with npts=11 (that is, the initial command shown in the sandbox), what is the horizontal spacing between the discrete \(x\) values?

0.5 1 2 4 5

Now take away the npts= argument. This will implicitly set npts to a default value, which is what we have been using for most plots in this course.

Part B What is the default value of npts in slice_plot()?

25 50 100 200 500 1000

We could use a much larger value for npts, but there is no reason so long as a smaller value produces a graph faithful to the function being graphed.

Keeping the domain the same, \(1 \leq x \leq 21\), plot out a sinusoid with a period of 0.3 using the default npts: \(g(x) \equiv \sin(2\pi x/0.3)\). The graph, which shows about 67 cycles of the sinusoid, will not look much like a sinusoid. In particular, although the sine function should reach from -1 to 1 over each cycle, the graph does not.

Part C How large should npts be in order for each of the 67 cycles in the graph to come close enough to -1 and 1 that you cannot easily see the discrepancy?

125 150 200 400 800 1600 3200

Exercise 37.07

Methods such as Euler are tedious, ideal for the computer. So let’s look at some basic R functions for implementing the Euler Method when we know the function to be anti-differentiated \(f(x)\), the step size \(h\), and the domain \(a \leq x \leq b\). At the heart of the implementation is a function cumsum(), the “cumulative sum.” This does something very simple. The cumulative sum of the sequence 1, 2, 3, 4 is another sequence: 1, 3, 6, 10.

The following code has commands for using cumsum() to approximate the anti-derivative of a function \(f()\) over the domain \(a \leq x \leq b\).

f <- makeFun(sin(2*pi*x/0.3) ~ x) # the function to be anti-differentiated.
a <- 1 # the lower bound.
b <- 2 # the upper bound.
h <- 0.01 # the step size
x_discrete <- seq(a, b, by = h) # all of the discrete x values based on a, b, and h
f_discrete <- f(x_discrete) # all of the values of f(x) when the discrete x values are used as the input
F_discrete <- cumsum(h * f_discrete) # the discrete values of the anti-derivative, F(x)
gf_point(F_discrete ~ x_discrete) %>%
  slice_plot(f(x) ~ x, color = "gray", bounds(x=c(a,b)))

Here is a function:

g <- makeFun(exp(-0.2*(x^2))~x)

Using a SANDBOX, find and plot the anti-derivative of \(g(x)\) over the domain \(-6 \leq x \leq 6\).

Your task: Describe the shape of \(G(x)\). Your description can be one word from earlier in the book, if you choose it carefully. If your graph looks like a straight line, you did not appropriately change the domain above.

Exercise 37.08

The graphic, from The Economist news magazine, shows the number of elective treatments (e.g. minor surgery, etc.) by the British National Health Service over the period January 2019 to April 2021. The point of the graph is to show the extent to which people avoided medical treatment due to the Covid-19 pandemic, which started to become severe in March 2020. (The January/February treatment numbers for 2020 line up pretty exactly with the 2019 numbers.)

knitr::include_graphics(normalizePath("www/NHS.png"))

Part A According to the graphic, how many fewer treatements were there in the 12 months of 2020 compared to the 12 months of 2019? (Choose the best of the following answers.)

About 500,000 About 2,000,000 About 6,000,000 About 10,000,000


  1. The root of the word “data” is the Latin for “given”.↩︎