4 Product rule and function of function or chain rule.
Contents
4 Product rule and function of function or chain rule.#
# import all python add-ons etc that will be needed later on
%matplotlib inline
import numpy as np
import matplotlib.pyplot as plt
from sympy import *
from scipy.optimize import fsolve # use this for numerical solution
init_printing() # allows printing of SymPy results in typeset maths format
plt.rcParams.update({'font.size': 14}) # set font size for plots
Many equations have the form where a power of
These are the product rule, which is used when there is a function that is a product or ratio of other functions e.g.
4.1 Function-of-a-function or Chain rule#
The method when one function is a function of another is to
differentiate the main or ‘outside function’, then multiply this by the differential of the inside function.
This simple but powerful method is most easily explained by examples; (i) to (iv) below are typical. The general formula is given in the next section. To differentiate the functions, use the table or various sections above to remind you of the rules.
(a) To differentiate
differentiating the outside first, then the inside
(b)
(c)
which can be checked using the result for logs.
(d) In this example
because
and
Taking the
which should be the same result as was obtained by using the first method but substitution and rearranging is necessary to show this.
4.2 Function-of-a-function, general formula#
The general equation on which to use the function-of-function or chain rule is
Differentiation is performed by letting
and this formally expressed, is what was done in our previous examples. Notice how
In thermodynamics, derivatives often seem to appear out of nowhere. For instance,
and these are examples of the chain rule used in a way that you may feel is back to front. The left-hand side is expanded to give the right, rather than starting with an explicit function, of say,
4.3 The Product Rule#
When there are products or ratios of functions, differentiation is done in two steps;
Differentiate one function leaving the other alone.
Add to this the result of differentiating the second function, leaving the first alone.
An example should make this clear. To differentiate
As a check, expand the brackets to
4.4 General formula#
The general form of the product rule is:
where
then differentiating gives
and multiplying out gives equation 18.
Naturally the second derivative can be obtained by repeating the process:
An example using the function of function and the product rule is to find
4.5 Differentiating ratios of functions: Quotient rule.#
The product rule and function-of-function rule can be used to calculate quotients. If
which, if simplified, becomes
where the brackets and
and using eqn. 21
4.6 Differentiation with respect to a function#
Sometimes in thermodynamics, but also elsewhere, equations are put in the form
( i ) Example, Gibbs-Helmholtz eqn.#
To calculate this double reciprocal derivative we start with the Gibbs - Helmholtz equation. To obtain this we start with the basic equation
But as
where
Next the remaining derivative is substituted in,
and so;
So far, this is what we have done several times in one form or another. The next step is to find the derivative with respect to
(ii) Example, van’t Hoff isotherm#
A second commonly met equation is the van’t Hoff isotherm
which describes how the equilibrium constant of a reaction at constant pressure
Therefore, a plot of the log of the equilibrium constant vs reciprocal temperature is a horizontal line of intercept
(iii) Example found in Euler-Lagrange eqns.#
In the study of mechanics, i.e. the motion of the pendulum, and of planets etc, the Euler-Lagrange equation is of considerable utility as demonstrated in section 6 of this chapter (Calculus of Variations). This equation has the form
where
then
and taking the time derivative
which is the second derivative if
4.7 Implicit differentiation#
Quite often, an equation we may want to differentiate contains powers or functions of
Differentiating
To test how well you understand this, find
An apparently hard differentiation is to find
which can be simplified to
SymPy produces the same result after a little simplification and remembering that the function equals zero and that x^x=y^y$.
x,y = symbols('x,y')
y = Function('y') # define y to be a function
f = y(x)**y(x) - x**x # define this as a function not an equation
ans = diff(f,x) # define y as a function of x so that it will be differentiated.
simplify(ans)

4.8 Differentiating parametric functions#
Sometimes it is easier to describe equations in parametric form as two functions with a common or dummy variable, rather than in the conventional way; there is no fundamental reason for doing so, just convenience. An example is the equation of a circle. If it has a radius
In parametric form, this same equation becomes the pair of equations;
with
When graphing a parametric equation both
The parametric equations of an ellipse are
To differentiate the parametric form use the function-of-function approach and write
Therefore,
The second derivative can be written, using
evaluating the last step gives
As a check we can use SymPy.
x,y,t = symbols('x y t')
y = Function('y')
x = Function('x')
ans = diff( diff(y(t),t)/diff(x(t),t) , t) / diff(x(t),t)
simplify(ans)

Consider finding the gradient of the elegant looking curve shown in Fig. 6 at a point such as
The gradient from equation (23) is
To reform this into an equation in
f = lambda t: t**3-t-2 # define function so fsolve knows what to solve for
ans = fsolve(f,1)[0] # use [0] to get first answer only, answer is t
print('real root of equation = ',ans)
print('gradient = ', 4*ans*np.cos(ans**2)/(3*ans**2-1))
print('y0 = ', 2*np.sin(ans**2))
real root of equation = 1.5213797068045676
gradient = -0.6932343858343518
y0 = 1.4718020332688042
Figure 6. Left. The parametic curve and tangent at
There must the three solutions but only the real value,
The horizontal and vertical tangents can be obtained from the individual derivatives when
and so forth for other tangents. The vertical tangent occurs at
(i) Calculating the Parametric Equation#
As an example consider finding the parametric equations of an epicycloid. This is the curve formed when one disc rotates about another, such as two coins. In the (false) models of the solar system, such as proposed by Ptolemy, epicycloids were used to describe the motion of the planets. Initially these worked quite well but as time passes such models, based as they were on incorrect physics, became increasingly inaccurate. If the epicycloid curve produced has one cusp it is called a cardioid due to its heart-like shape, those with two cusps are called nephroids after the shape of a kidney. Figure 6a shows two epicycloids, the number of cusps corresponds to the ratio of radii.
Figure 6a. Epicycloids. Left The cardioid is the black curve (radio of radii is 1) and right Nephroid (black ) with ratio 2.
Assuming that the fixed circle is centred at the origin of the coordinates (fig. 6b), the parameter
We start by writing down the lengths AB and BC which are
Finally, if there are two similar coins and if one rotates (without slipping) half way round the other what direction will it now point compared to that initially? The answer is that it will point in the same direction as that when it started. The distance travelled is
Figure 6b. Calculation of parametric equation for an epicycle.
4.9 Differentiating vectors#
To differentiate any vector, each of its elements is treated separately. In the previous section, we saw how to represent a curve in parametric form. The two parametric equations can also be represented in vector form; for example, a parabola is represented by the equation
Evaluating each term produces
4.10 Differentiating dot and cross products#
When differentiating dot and cross products, the normal differentiation and the normal vector rules apply. Suppose
Similarly for the cross product
Differentiating vectors is described in more detail in Section 13.
5 Differentiation summary#
Notation