23 Derivatives of assembled functions
In Chapter 19 we used the rules associated with evanescent
23.1 Using the rules
When you encounter a function that you want to differentiate, you first have to examine the function to decide which rule you want to apply. In the following, we will to use the names
Step 1: Identify f() and g()
We will write the rules in terms of two function names,
In general,
Step 2: Find f’() and g’()
For differentiating either products or compositions, you will need to identify both
Step 3: Apply the relevant rule
Recall from Chapter ?sec-fun-assembling that will will be working with three important forms for creating new functions out of existing functions:
- Linear combinations, e.g.
- Products of functions, e.g.
- Compositions of functions, e.g.
23.2 Differentiating linear combinations
Linear combination is one of the ways in which we make new functions from existing functions. As you recall, linear combination involves scaling functions and then adding the scaled functions as in
Now consider the derivative of the sum of two functions,
Because of how
We can summarize the h-theory result for linear combinations this way:
The derivative of a linear combination is the linear combination of the derivatives.
That is:
as well as
The derivative of a polynomial is a polynomial of a lower order.
Consider the polynomial
23.3 Product rule for multiplied functions
The question at hand is how to compute the derivative
This situation arises particularly when
The purpose of this section is to derive the formula for
As with all derivatives, the product rule is based on the instantaneous rate of change
We also need two other statements about
- The derivative
is the slope of of at input . Taking a step of size from will induce a change of output of , so - Any result of the form
, where is finite, gives 0. More precisely,
As before, we will put the standard
Suppose the function
We will replace
This has two bracketed terms added together over a common denominator. Let’s split them into separate terms:
The first term is
In each of the last two terms there is an
The last step relies on statement (2) above.
Some people find it easier to read the rule in Lagrange shorthand, where
The expression
Occasionally, mathematics gives us a situation where being more general produces simplicity.
In the case of function products, the generalization is from products of two functions
The chain rule here takes a form that makes the overall structure much clearer:
In the Lagrange shorthand, the pattern is even more evident:
23.4 Chain rule for function composition
A function composition, as described in Section 9.2, involves inserting the output of one function (the “interior function”) as the input of the other function (the “exterior function”). As we so often do, we will be using pronouns a lot. A list might help keep things straight:
- There are two functions involved in a composition. Generically, we call them
and . In the composition , the exterior function is and the interior function is . - Each of the two functions
and has an input. In our examples, we use to stand for the input to the exterior function and for the input to the interior function. - As with all rules for differentiation, we will need to compute the derivatives of the functions involved, each with respect to its own input. So these will be
and .
A reason to use different pronouns for the inputs to
With this distinction between the names of the inputs, we can be even more explicit about the composition, writing
With all these pronouns in mind, here is the chain rule for the derivative
Or, using the Lagrange prime notation, where
23.5 Rates per time
In news and policy discussions, you will often hear about “inflation rate” or “birth rate” or “interest rate” or “investment rate of return.” In each case, there is a function of time combined with a derivative of that function: with the general form
- Inflation rate: The function is cost_of_living(
). The derivative is the rate of change with respect to time in the cost of living: cost_of_living( ). - Birth rate: The function is population(
). The derivative is population( ), or at least that component of the overall population( ) that is related to births. (Other components are deaths and the balance of in-migration and out-migration.) - Interest rate: The function is account_balance(
) and the derivative is account_balance( ). - Investment returns: The function is net_worth(
) and the derivative is net_worth( ).
In all these cases, The “rate” is not merely “per time” as would be the case for
Notice the two uses of “per” in the phrase: “births per capita per year.” A proportional rate is two rates in one. Births per capita is a proportion of the population. Births per year is an average rate with respect to time. But “births per capita per year” is a rate in the proportion with respect to time.
The rate word “per” also appears as part of “percent,” which literally means “per hundred.” A “percentage change” is the amount of change divided by the base amount. Confusingly, perhaps, “percentage change” is often truncated to the shorter “percent.” This is the case with inflation rates, interest rates, and rates of return on investment. The interest rate on a credit-card debt is stated as a proportion of the current debt; all that is packed into the word “percent.” The interest rate itself is the “proportion of the current debt per year”: two rates in one.
Similarly for an inflation rate. “Inflation” is stated as the change in prices divided by the current price: a proportional change. “Inflation rate” is the proportional change per unit of time, where the “whole” is current prices and the rate is change in current prices per year divided by current prices.
Thanks to the chain rule, there is a shortcut way of writing proportional rates per time. Exactly equivalent to the ratio
Derivatives of logarithms appear often in fields such as economics or finance, where it is common to consider the logarithm of the economic quantity to render changes as percent of the whole.
The derivation of the chain rule relies on two closely related statements which are expressions of the idea that near any value
, which is the same thing as (1) but uses as the argument name and to stand for the small quantity we usually write with an .
We will now look at
Let’s examine closely the expression
We will substitute the
In the denominator,
Use the chain rule to find the derivative
Recognize that
Recognizing
The chain rule can be used in a clever way to find a formula for
We’ve already seen that the logarithm is the inverse function to the exponential, and vice versa. That is:
Since
Let’s differentiate the second form using the chain rule:
Whatever the function
Knowing that
The rules of exponents allow us to recognize
Applying the chain rule to this composition gives
.
23.6 Derivatives of the basic modeling functions
The basic modeling functions are the same as the pattern-book functions, but with bare
Suppose
Here are the steps for differentiating a basic modeling function
- Step 1: Identify the particular pattern-book function
and write down its derivative . For example, if is , then is . - Step 2: Find the derivative of the linear interior function. If the function is
, then the derivative is . If the interior function is , the derivative is . - Step 3: Write down the original function
but replace with and pre-multiply by the derivative of the interior function. For instance, Another example:
By convention, there are different ways of writing
Pattern-book function |
Basic modeling |
---|---|
The rule for the derivative of any basic modeling function
To illustrate:
where . where . where . where and we use the fact that .
You will be using the derivatives of the basic modeling functions so often, that you should practice and practice until you can write the derivative at a glance.
There are many possible implementations of the general concept of hump functions and sigmoid functions. This book uses
The names
In statistical nomenclature, dnorm()
and pnorm()
.
Owing to the origin of the names
Composition or product?
There is one family of functions for which function composition accomplishes same thing as multiplying functions: the power-law family.
Consider, for instance, the function
Recognizing that
These are two long-winded ways of getting to the result. For most people, differentiating power-law functions algebraically is simplified by using the rules of exponentiation rather than the product or chain rule. Here,
As another example, take
23.7 Exponentials and logarithms (optional)
The natural logarithm function, log10(x)
. Ten is an integer, and a nice number to use in arithmetic. So in practice, it is sensible to use
The “natural” in the “natural logarithm” means something different.
The base of the natural logarithm is the number called Euler’s constant and written
It is not obvious why
is the inverse of , which is special for being invariant under differentiation: .- The derivative
which has a particularly simple form, namely, .
Let’s look at the log-base-10 and its computer-savvy cousin log-base-2. The very definition of logarithms means that both 10 and 2 can be written
Calculating
and
Like
23.8 Drill
Part 1 Which of the derivative rules should you use to find
- The constant multiplier rule
- The linear combination rule
- The product rule
- The chain rule
- No rule needed, it is so basic.
Part 2 Which of the derivative rules should you use to find
- The constant multiplier rule
- The linear combination rule
- The product rule
- The chain rule
- No rule needed, it is so basic.
Part 3 Which of the derivative rules should you use to find
- The constant multiplier rule
- The linear combination rule
- The product rule
- The chain rule
- No rule needed, it is so basic.
Part 4 Which of the derivative rules should you use to find
- The constant multiplier rule
- The linear combination rule
- The product rule
- The chain rule
- No rule needed, it is so basic.
Part 5 Which of the derivative rules should you use to find
- The constant multiplier rule
- The linear combination rule
- The product rule
- The chain rule
- No rule needed, it is so basic.
Part 6 Which of the derivative rules should you use to find
- The constant multiplier rule
- The linear combination rule
- The product rule
- The chain rule
- No rule needed, it is so basic.
Part 7 Which of the derivative rules should you use to find
- The constant multiplier rule
- The linear combination rule
- The product rule
- The chain rule
- No rule needed, it is so basic.
Part 8 Which of the derivative rules should you use to find
- The constant multiplier rule
- The linear combination rule
- The product rule
- The chain rule
- No rule needed, it is so basic.
Part 9 Which of the derivative rules should you use to find
- The constant multiplier rule
- The linear combination rule
- The product rule
- The chain rule
- No rule needed, it is so basic.
Part 10 What is
Part 11 What is
- 0
- -1
Part 12 What is
Part 13 Which of these is
Part 14 Which of these is
Part 15 Which of these is
Part 16 What is
Part 17 What is
Part 18 The derivative
Part 19 What is
Part 20 What is
Part 21 For the function
Yes No
Part 22 For the function
Yes No
Part 23 For the function
Yes No
Part 24 For the function
Yes No
Part 25 Saying “the interior function is linear” is not an entirely complete statement. A full statement is “the interior function is linear in terms of the input
Is the expression
Yes No
Part 26 Saying “the interior function is linear” is not an entirely complete statement. A full statement is “the interior function is linear in terms of the input
Is the expression
Yes No
Part 27 Saying “the interior function is linear” is not an entirely complete statement. A full statement is “the interior function is linear in terms of the input
Is the expression
Yes No
23.9 Exercises
Exercise 23.01
Section 23.1 explains that in differentiating a linear combination of two functions, or a product of two functions, or one function composed with another, your first task is to identify the two functions
Carry out these two tasks for each of the combined functions shown in the table. (The first row has been done for you as an example.)
Combination | ||||
---|---|---|---|---|
Exercise 23.02
For each of the following, say whether the function is a composition
Part A What sort of combination is
product composition neither
Part B What sort of combination is
product composition neither
Part C What sort of combination is
product composition neither
Part D What sort of combination is
product composition neither
Part E What sort of combination is
product composition neither
Part F What sort of combination is
product composition neither
Part G What sort of combination is
product composition neither
Part H What sort of combination is
product composition neither
Part I What sort of combination is
product composition neither
Exercise 23.03
Consider this function,
As you know, the derivative of a sigmoid
Part A How many gaussians will be in
2 3 6 none
The following figure shows several functions. One of them is
Part B Which function is the actual derivative of
A B C D
Part C Of the functions (1), (2), (3), and (4) below, which function is the second derivative of
(1) (2) (3) (4)
Exercise 23.04
In function compositions of the form
Part A In
- None of the above
- It is not a function composition
Part B In
- None of the above
- It is not a function composition
Part C In
- None of the above
- It is not a function composition
Part D In
- None of the above
- It is not a function composition.
Part E In
- None of the above
- It is not a function composition.
Exercise 23.06
Compare the functions
to construct the plot, you will have to pick specific values for
<- makeFun(dnorm(x, mn, sd) ~ x, mn=2, sd=3)
f1 <- makeFun(dnorm( (x-mn) / sd) ~ x, mn=2, sd=3) f2
Part A When
- Yes
- Yes, but only if
- Yes, but only if
- No
Part B When
Exercise 23.08
Pilots of commercial passenger aircraft consider the comfort of their passengers into account when flying. In transitioning from level flight onto the descent path for landing, for example, pilots take care that the vertical component of acceleration isn’t so great that passengers feel the plane “falling out from under them.”
A simple model of the descent path is a sigmoid function. Suppose that the descent starts from an altitude of
The vertical acceleration is the second derivative of alt() with respect to time:
to treat alt() as a function of time, we need to write “distance from the runway” as a function of time. Let’s set
Suppose that the aircraft is flying at
Using a sandbox, plot out the function alt(
<- makeFun(20000 * pnorm(30000 - v * t, 30000/2, 30000/6) ~ t, v = 293.3)
alt slice_plot(alt(t) ~ t, bounds(t=0:110))
Compute the second derivative numD()
rather than D()
to compute the second derivative.)
Graph the second derivative over the appropriate domain and look for the most extreme values of acceleration.
<- numD(alt(t) ~ t + t)
dd_alt slice_plot(dd_alt(t) ~ t, bounds(t=0:110))
From the graph, read off the maximum vertical acceleration during the descent.
Part A What are the units of vertical acceleration shown in the graph?
- feet-per-second
- feet-per-second-squared
- miles-per-hour-squared
A rule of thumb is that a vertical acceleration up to
Part B How far from the foot of the runway should descent begin to stay within the
40,000 ft 50,000 ft 60,000 ft 70,000 ft 80,000 ft
For reflection: A new hire at the airline’s operations center proposes to model the descent as a straight-line function rather than a sigmoid. He points out that the second derivative of a straight-line function is always 0, so the passengers would feel no acceleration at all! Explain to this newbie what’s wrong with his idea.
Exercise 23.09
In Exercise none yet, E9e7c6 you constructed models
<- makeFun(ifelse(t < 0, 0, exp(-k * t)) ~ t, k = log(2)/3) pill
The parameter
The model for the entire regiment is a linear combination of time-shifted single pills, e.g.
<- makeFun(A*pill(t) + A*pill(t-8) + A*pill(t-16) + A*pill(t-24) + A*pill(t-32) ~ t, A=1) regimen8
From graphs of the functions themselves it is easy to check whether the availability ever falls below the therapeutic threshold (which we stipulated is 0.25). For instance, the eight-hour regiment with a dose of A=1
does fall below the threshold during the first day. So a larger dose is needed than A=1
.
The derivative
For each of the three regimens, construct
. Ignoring the glitches due to discontinuity at the times the pills are consumed, which of the three regimens has the lowest average rate of drug elimination?
Exercise 23.10
Recall from Section 9.2 the Lorenz curve used to describe income inequality. The Lorenz curve shows the fraction of total income versus population fraction.
Since the population is arranged from poorest to richest along the horizontal axis, Lorenz curves must be both monotonically increasing and concave up. That is, any Lorenz function
that is, the aggregate fraction of income earned by the entire population is 100%. that is, monotonically increasing that is, concave up.
Consider a function
- A. Use the composition rule to show that
is monotonically increasing. (Hint, calculate and show that it must be positive.) - B. Using both the composition and product rules, calculate
and show that must be concave up.
Exercise 23.12
The formula for the function
A. Use the chain rule to find
B. Confirm from your answer to (1) that there is another formula for
C. Use the product rule to find
D. From your answer to (3), compute the 3rd derivative
E. Let’s generalize the pattern. Each of the previous derivatives has been a polynomial—let’s call it
We know
Exercise 23.14
Confirm using algebraic manipulation the differentiation rule for a product of three functions:
Here,
Hint: