22 Continuity and smoothness
You have seen how various properties of a function—whether it is monotonic, how it slopes, whether it is concave up or down (or not at all), curvature, etc.—can be related to the first and second derivatives of the function.
In this chapter, we will elaborate on continuity, one of the ideas introduced in ?sec-word-descriptions, and use the concept of continuity to characterize functions in a new way: their smoothness.
22.1 Continuity
The intuition behind continuity is simple: If you can draw the graph of a function without lifting the pencil from the paper, the function is continuous.
Continuity can be an important attribute of a modeling function. Often, we expect that a small change in input produces a small change in output. For instance, if your income changes by one penny, you would expect your lifestyle not to change by much. If the temperature of an oven changes by 1 degree, you don’t expect the quality of the cake you are baking to change in any noticeable way.
All of our basic modeling functions are continuous over their entire input domain.1 To illustrate discontinuity we will consider piecewise functions, as introduced in Section 9.4. The Heaviside function, graphed in Figure 22.1 is discontinuous.
Drawing the graph of the Heaviside function
In contrast, the piecewise ramp function (Figure 22.2) is continuous; you don’t need to lift the pencil from the paper to draw the ramp function.
Imagine that you were constructing a model of plant growth as a function of the amount of water (in cc) provided each day. The plant needs about 20 cc of water to thrive. You use the Heaviside function for the model, say
Common sense suggests that a change of 0.002 cc in the amount of water—a small fraction of a drop, 2 cubic millimeters of volume—is not going to lead to a qualitative change in output. So you might prefer to use a sigmoid function as your model rather than a Heaviside function.
On the other hand, sometimes a very small change in input does lead to a large change in output. For instance, a sensible model of the hardness of water as a function of temperature would include a discontinuity at
One of author Charles Dickens’s famous characters described the relationship between income, expenditure, and happiness this way:
“Annual income 20 pounds, annual expenditure 19 [pounds] 19 [shillings] and six [pence], result happiness. Annual income 20 pounds, annual expenditure 20 pounds ought and six, result misery.” — the character Wilkins Micawber in David Copperfield
Macawber referred to the common situation in pre-20th century England of putting debtors in prison, regardless of the size of their debt. Macawber’s statement suggests he would model happiness as a Heaviside function
Whenever the output of a function is a binary (yes-or-no) value, you can anticipate that a model will involve a discontinuous function.
22.2 Discontinuity
Recall the logical path that led us to the idea of the derivative of a function. We started with the differencing operator, which takes as input a function and a “small” value of
Then, through algebraic manipulation and numerical experiments we found that, once
Conveniently, we found that the derivatives of the pattern-book functions can be written in terms of the pattern-book functions without making any reference to
No appears. No appears No appears.- and so on.
With discontinuous functions, we have no such luck. Figure 22.3 shows what happens if we compute
<- makeFun(ifelse(x >=0, 1, 0) ~ x)
H <- makeFun((H(x + 0.1) - H(x))/0.1 ~ x)
DH01 <- makeFun((H(x + 0.01) - H(x))/0.01 ~ x)
DH001 <- makeFun((H(x + 0.001) - H(x))/0.001 ~ x)
DH0001 slice_plot(DH01(x) ~ x, bounds(x=-0.02:0.02),
npts=500, color="red", size=2) %>%
slice_plot(DH001(x) ~ x,
color="darkgreen", npts=500, size=3, alpha=0.5) %>%
slice_plot(DH0001(x) ~ x,
color="blue", npts=500, alpha=0.5, size=2)
Differencing the Heaviside function produces very different functions depending on the value of
Since there is no convergence in the shape of
22.3 Smoothness
Smoothness is a different concept than continuity, although the two are related. Most simply, any discontinuous function is not smooth at any input where a discontinuity occurs. But even the continuous ramp function is not smooth at the start of the ramp. Intuitively, imagine you were sliding your hand along the ramp function. You would feel the crease at
A function is not smooth if the derivative of that function is discontinuous. For instance, the derivative of the ramp function is the Heaviside function, so the ramp is not smooth at
All of our basic modeling functions are smooth everywhere in their domain. In particular, the derivatives of the basic modeling functions are continuous, as are the second derivative, third derivative, and so on down the line. Such functions are called C-infinity, written
You cannot tell from the plot that the second derivative is discontinuous. But if you were in a plane flying along that trajectory, you would feel a jerk as you crossed
Mathematicians quantify the “smoothness” of a function by looking at the function’s continuity and the continuity of its derivatives. Smoothness is assessed on a scale
: the function is continuous. Intuitively, this means that the function’s graph can be drawn without lifting the pencil from the paper. : the function has a derivative over its entire domain and that derivative is continuous. (See ?fig-c1-function for an example.) : the function has a derivative over its entire domain and that derivative is continuous. In other words, exists and is continuous. : Like , but we are talking about the th-derivative of existing and being continuous. : Usually when we denote a sequence with an infinite number of terms, we write down something like . It would be entirely valid to do this in talking about the sequence. But many of the mathematical functions we work with are infinitely differentiable, that is .
Examples of
: the derivatives are , , , , … You can keep going infinitely. : the derivatives are , , and so on. : the derivatives are , , , … Higher order derivatives are all simply 0. Boring, but still existing.
Example of non-
, the absolute value function. is a pasting together of two functions: The domain is split at .
For engineering and design problems, smoothness means something substantially different than described by the mathematical concepts above. In Chapter Chapter 48 we will introduce cubic splines which are continuous functions defined by a finite set of coordinate pairs: two variables of a data frame. Each line of the data frame specifies a “knot point.” The spline consists of ordinary cubic polynomials drawn piecewise between consecutive knot points. At a knot point, the cubics on either side have been arranged to have their first and second derivatives match. Thus, the first two derivatives are continuous. The function is at least
22.4 Exercises
Exercise 22.01
Draw the graph of a function from your imagination over the domain
. The function should be continuous everywhere except at .Draw the graph of a second function from your imagination over the same domain as in (1). The second function should be continuous everywhere in domain: no discontinuities. It should also have a derivative everywhere except at
.
Exercise 22.02
For the sketched functions below, decide what level of smoothness—
Part A What’s the smoothness level of function A(x)? (Hint: A quadratic function has a first derivative that changes with x but a second derivative that is constant for all x.)
discontinuous
Part B What’s the smoothness level of function B(x)?
discontinuous
Part C What’s the smoothness level of function C(x)?
discontinuous
Part D What’s the smoothness level of function D(x)?
discontinuous
Exercise 22.03
The ramp function is defined algebraically as
or in R as ::: {.cell layout-align=“center” fig.showtext=‘false’}
<- makeFun(ifelse(x<0, 0, x) ~ x) ramp
:::
Evaluate these three different forms for the definition of the instantaneous rate of change at
- version 1:
- version 2:
- version 3:
Part A Do the three versions give different numerical results at
- They all give the same result.
- Versions 1 and 3 give the same result, but 2 is different.
- Versions 1 and 2 give the same result, but 3 is different.
- All three are different
Part B For much smaller
Yes No
Exercise 22.04
Consider this function, defined piecewise:
Write the R command to create this function. (Hint: Remember
ifelse
from Section 9.4.)Using a SANDBOX, plot
over the domain , then sketch a copy of the graph on your paper.Create the function
by differentiating separately each piece of the piecewise function . Write down using mathematical notation similar to the definition of given above.Sketch a graph of
over the domain . You’re welcome to use a SANDBOX, but you may be able to figure out the shape of the graph yourself.The shape of the function you sketched in (4) has a name, given in the text in Section @ref(continuity). What is that name?
Now you will do much the same as in items (3), (4), and (5), but instead of the first derivative
Create and write down
in mathematical notation.Sketch
Classify the smoothness of
using the following table:
Smoothness | Criterion |
---|---|
and so on. | |
All orders of derivative of |
Exercise 22.05
Consider the following functions
Part A How smooth is
discontinuous
Part B How smooth is
discontinuous
Part C How smooth is
discontinuous
Part D How smooth is
discontinuous
Part E How smooth is
discontinuous
Part F How smooth is
discontinuous
Part G How smooth is
discontinuous
Part H How smooth is
discontinuous
The domain of the function
is the whole number line, except 0, where the positive and negative branches fail to meet up.↩︎