# Calculus/Chain Rule

The chain rule is a method to compute the derivative of the functional composition of two or more functions.

If a function, ${\displaystyle f}$ , depends on a variable, ${\displaystyle u}$ , which in turn depends on another variable, ${\displaystyle x}$ , that is ${\displaystyle f=y{\bigl (}u(x){\bigr )}}$ , then the rate of change of ${\displaystyle f}$ with respect to ${\displaystyle x}$ can be computed as the rate of change of ${\displaystyle y}$ with respect to ${\displaystyle u}$ multiplied by the rate of change of ${\displaystyle u}$ with respect to ${\displaystyle x}$ .

 Chain Rule If a function ${\displaystyle f}$ is composed to two differentiable functions ${\displaystyle y(x)}$ and ${\displaystyle u(x)}$ , so that ${\displaystyle f(x)=y{\bigl (}u(x){\bigr )}}$ , then ${\displaystyle f(x)}$ is differentiable and, ${\displaystyle {\frac {df}{dx}}={\frac {dy}{du}}\cdot {\frac {du}{dx}}}$

The method is called the "chain rule" because it can be applied sequentially to as many functions as are nested inside one another.[1] For example, if ${\displaystyle f}$ is a function of ${\displaystyle g}$ which is in turn a function of ${\displaystyle h}$ , which is in turn a function of ${\displaystyle x}$ , that is

${\displaystyle f{\bigl (}g(h(x)){\bigr )}}$

the derivative of ${\displaystyle f}$ with respect to ${\displaystyle x}$ is given by

${\displaystyle {\frac {df}{dx}}={\frac {df}{dg}}\cdot {\frac {dg}{dh}}\cdot {\frac {dh}{dx}}}$ and so on.

A useful mnemonic is to think of the differentials as individual entities that can be canceled algebraically, such as

${\displaystyle {\frac {df}{dx}}={\frac {df}{\cancel {dg}}}\cdot {\frac {\cancel {dg}}{\cancel {dh}}}\cdot {\frac {\cancel {dh}}{dx}}}$

However, keep in mind that this trick comes about through a clever choice of notation rather than through actual algebraic cancellation.

The chain rule has broad applications in physics, chemistry, and engineering, as well as being used to study related rates in many disciplines. The chain rule can also be generalized to multiple variables in cases where the nested functions depend on more than one variable.

## Examples

### Example I

Suppose that a mountain climber ascends at a rate of 0.5 kilometer per hour. The temperature is lower at higher elevations; suppose the rate by which it decreases is 6°C per kilometer. To calculate the decrease in air temperature per hour that the climber experiences, one multiplies 6°C per kilometer by 0.5 kilometer per hour, to obtain 3°C per hour. This calculation is a typical chain rule application.

### Example II

Consider the function ${\displaystyle f(x)=(x^{2}+1)^{3}}$ . It follows from the chain rule that

 ${\displaystyle f(x)=(x^{2}+1)^{3}}$ Function to differentiate ${\displaystyle u(x)=x^{2}+1}$ Define ${\displaystyle u(x)}$ as inside function ${\displaystyle f(x)=u(x)^{3}}$ Express ${\displaystyle f(x)}$ in terms of ${\displaystyle u(x)}$ ${\displaystyle {\frac {df}{dx}}={\frac {df}{du}}\cdot {\frac {du}{dx}}}$ Express chain rule applicable here ${\displaystyle {\frac {df}{dx}}={\frac {d}{du}}u^{3}\cdot {\frac {d}{dx}}(x^{2}+1)}$ Substitute in ${\displaystyle f(u)}$ and ${\displaystyle u(x)}$ ${\displaystyle {\frac {df}{dx}}=3u^{2}\cdot 2x}$ Compute derivatives with power rule ${\displaystyle {\frac {df}{dx}}=3(x^{2}+1)^{2}\cdot 2x}$ Substitute ${\displaystyle u(x)}$ back in terms of ${\displaystyle x}$ ${\displaystyle {\frac {df}{dx}}=6x(x^{2}+1)^{2}}$ Simplify.

### Example III

In order to differentiate the trigonometric function

${\displaystyle f(x)=\sin(x^{2})}$

one can write:

 ${\displaystyle f(x)=\sin(x^{2})}$ Function to differentiate ${\displaystyle u(x)=x^{2}}$ Define ${\displaystyle u(x)}$ as inside function ${\displaystyle f(x)=\sin(u)}$ Express ${\displaystyle f(x)}$ in terms of ${\displaystyle u(x)}$ ${\displaystyle {\frac {df}{dx}}={\frac {df}{du}}\cdot {\frac {du}{dx}}}$ Express chain rule applicable here ${\displaystyle {\frac {df}{dx}}={\frac {d}{du}}\sin(u)\cdot {\frac {d}{dx}}(x^{2})}$ Substitute in ${\displaystyle f(u)}$ and ${\displaystyle u(x)}$ ${\displaystyle {\frac {df}{dx}}=\cos(u)\cdot 2x}$ Evaluate derivatives ${\displaystyle {\frac {df}{dx}}=\cos(x^{2})\cdot 2x}$ Substitute ${\displaystyle u}$ in terms of ${\displaystyle x}$ .

### Example IV: absolute value

The chain rule can be used to differentiate ${\displaystyle |x|}$ , the absolute value function:

 ${\displaystyle f(x)=|x|}$ Function to differentiate ${\displaystyle f(x)={\sqrt {x^{2}}}}$ Equivalent function ${\displaystyle u(x)=x^{2}}$ Define ${\displaystyle u(x)}$ as inside function ${\displaystyle f(x)=u(x)^{\frac {1}{2}}}$ Express ${\displaystyle f(x)}$ in terms of ${\displaystyle u(x)}$ ${\displaystyle {\frac {df}{dx}}={\frac {df}{du}}\cdot {\frac {du}{dx}}}$ Express chain rule applicable here ${\displaystyle {\frac {df}{dx}}={\frac {d}{du}}u^{\frac {1}{2}}\cdot {\frac {d}{dx}}(x^{2})}$ Substitute in ${\displaystyle f(u)}$ and ${\displaystyle u(x)}$ ${\displaystyle {\frac {df}{dx}}={\frac {u^{-{\frac {1}{2}}}}{2}}\cdot 2x}$ Compute derivatives with power rule ${\displaystyle {\frac {df}{dx}}={\frac {(x^{2})^{-{\frac {1}{2}}}}{2}}\cdot 2x}$ Substitute ${\displaystyle u(x)}$ back in terms of ${\displaystyle x}$ ${\displaystyle {\frac {df}{dx}}={\frac {x}{\sqrt {x^{2}}}}}$ Simplify ${\displaystyle {\frac {df}{dx}}={\frac {x}{|x|}}}$ Express ${\displaystyle {\sqrt {x^{2}}}}$ as absolute value.

### Example V: three nested functions

The method is called the "chain rule" because it can be applied sequentially to as many functions as are nested inside one another. For example, if ${\displaystyle f{\bigl (}g(h(x)){\bigr )}=e^{\sin(x^{2})}}$ , sequential application of the chain rule yields the derivative as follows (we make use of the fact that ${\displaystyle {\frac {d}{dx}}e^{x}=e^{x}}$ , which will be proved in a later section):

 ${\displaystyle f(x)=e^{\sin(x^{2})}=e^{g}}$ Original (outermost) function ${\displaystyle h(x)=x^{2}}$ Define ${\displaystyle h(x)}$ as innermost function ${\displaystyle g(x)=\sin(h)=\sin(x^{2})}$ ${\displaystyle g(h)=sin(h)}$ as middle function ${\displaystyle {\frac {df}{dx}}={\frac {df}{dg}}\cdot {\frac {dg}{dh}}\cdot {\frac {dh}{dx}}}$ Express chain rule applicable here ${\displaystyle {\frac {df}{dg}}=e^{g}=e^{\sin(x^{2})}}$ Differentiate f(g)[2] ${\displaystyle {\frac {dg}{dh}}=\cos(h)=\cos(x^{2})}$ Differentiate ${\displaystyle g(h)}$ ${\displaystyle {\frac {dh}{dx}}=2x}$ Differentiate ${\displaystyle h(x)}$ ${\displaystyle {\frac {d}{dx}}e^{\sin(x^{2})}=e^{\sin(x^{2})}\cdot \cos(x^{2})\cdot 2x}$ Substitute into chain rule.

## Chain Rule in Physics

Because one physical quantity often depends on another, which, in turn depends on others, the chain rule has broad applications in physics. This section presents examples of the chain rule in kinematics and simple harmonic motion. The chain rule is also useful in electromagnetic induction.

### Physics Example I: relative kinematics of two vehicles

One vehicle is headed north and currently located at (0,3); the other vehicle is headed west and currently located at (4,0). The chain rule can be used to find whether they are getting closer or further apart.

For example, one can consider the kinematics problem where one vehicle is heading west toward an intersection at 80mph while another is heading north away from the intersection at 60mph. One can ask whether the vehicles are getting closer or further apart and at what rate at the moment when the northbound vehicle is 3 miles north of the intersection and the westbound vehicle is 4 miles east of the intersection.

Big idea: use chain rule to compute rate of change of distance between two vehicles.

Plan:

1. Choose coordinate system
2. Identify variables
3. Draw picture
4. Big idea: use chain rule to compute rate of change of distance between two vehicles
5. Express ${\displaystyle c}$ in terms of ${\displaystyle x}$ and ${\displaystyle y}$ via Pythagorean theorem
6. Express ${\displaystyle {\frac {dc}{dt}}}$ using chain rule in terms of ${\displaystyle {\frac {dx}{dt}}}$ and ${\displaystyle {\frac {dy}{dt}}}$
7. Substitute in ${\displaystyle x,y,{\frac {dx}{dt}},{\frac {dy}{dt}}}$
8. Simplify.

Choose coordinate system: Let the ${\displaystyle y}$-axis point north and the x-axis point east.

Identify variables: Define ${\displaystyle y(t)}$ to be the distance of the vehicle heading north from the origin and ${\displaystyle x(t)}$ to be the distance of the vehicle heading west from the origin.

Express ${\displaystyle c}$ in terms of ${\displaystyle x}$ and ${\displaystyle y}$ via Pythagorean theorem:

${\displaystyle c=(x^{2}+y^{2})^{\frac {1}{2}}}$

Express ${\displaystyle {\frac {dc}{dt}}}$ using chain rule in terms of ${\displaystyle {\frac {dx}{dt}}}$ and ${\displaystyle {\frac {dy}{dt}}}$ :

 ${\displaystyle {\frac {dc}{dt}}={\frac {d}{dt}}(x^{2}+y^{2})^{\frac {1}{2}}}$ Apply derivative operator to entire function ${\displaystyle ={\frac {(x^{2}+y^{2})^{-{\frac {1}{2}}}}{2}}{\frac {d}{dt}}(x^{2}+y^{2})}$ Sum of squares is inside function ${\displaystyle ={\frac {(x^{2}+y^{2})^{-{\frac {1}{2}}}}{2}}\left[{\frac {d}{dt}}(x^{2})+{\frac {d}{dt}}(y^{2})\right]}$ Distribute differentiation operator ${\displaystyle ={\frac {(x^{2}+y^{2})^{-{\frac {1}{2}}}}{2}}\left[2x\cdot {\frac {dx}{dt}}+2y\cdot {\frac {dy}{dt}}\right]}$ Apply chain rule to ${\displaystyle x(t)}$ and ${\displaystyle y(t)}$ ${\displaystyle ={\frac {x\cdot {\frac {dx}{dt}}+y\cdot {\frac {dy}{dt}}}{\sqrt {x^{2}+y^{2}}}}}$ Simplify.

Substitute in ${\displaystyle x=4\ {\rm {mi}}\ ,\ y=3\ {\rm {mi}}\ ,\ {\frac {dx}{dt}}=-80\ {\rm {\frac {mi}{hr}}}\ ,\ {\frac {dy}{dt}}=60\ {\rm {\frac {mi}{hr}}}}$ and simplify

 ${\displaystyle {\frac {dc}{dt}}}$ ${\displaystyle ={\frac {4\ {\rm {mi}}\cdot \left(-80\ {\rm {\frac {mi}{hr}}}\right)+3\ {\rm {mi}}\cdot \left(60\ {\rm {\frac {mi}{hr}}}\right)}{\sqrt {(4\ {\rm {mi}})^{2}+(3\ {\rm {mi}})^{2}}}}}$ ${\displaystyle ={\rm {\frac {-320\ {\frac {mi^{2}}{hr}}+180\ {\frac {mi^{2}}{hr}}}{\sqrt {25\ mi}}}}}$ ${\displaystyle ={\rm {\frac {-140\ {\frac {mi^{2}}{hr}}}{5\ mi}}}}$ ${\displaystyle =-28\ {\rm {\frac {mi}{hr}}}}$

Consequently, the two vehicles are getting closer together at a rate of ${\displaystyle =28\ {\rm {\frac {mi}{hr}}}}$ .

### Physics Example II: harmonic oscillator

An undamped spring-mass system is a simple harmonic oscillator.

If the displacement of a simple harmonic oscillator from equilibrium is given by ${\displaystyle x}$ , and it is released from its maximum displacement ${\displaystyle A}$ at time ${\displaystyle t=0}$ , then the position at later times is given by

${\displaystyle x(t)=A\cos(\omega t)}$

where ${\displaystyle \omega ={\frac {2\pi }{T}}}$ is the angular frequency and ${\displaystyle T}$ is the period of oscillation. The velocity, ${\displaystyle v}$ , being the first time derivative of the position can be computed with the chain rule:

 ${\displaystyle v(t)={\frac {dx}{dt}}}$ Definition of velocity in one dimension ${\displaystyle ={\frac {d}{dt}}A\cos(\omega t)}$ Substitute ${\displaystyle x(t)}$ ${\displaystyle =A{\frac {d}{dt}}\cos(\omega t)}$ Bring constant ${\displaystyle A}$ outside of derivative ${\displaystyle =A{\bigl (}-\sin(\omega t){\bigr )}\cdot {\frac {d}{dt}}(\omega t)}$ Differentiate outside function (cosine) ${\displaystyle =-A\sin(\omega t)\cdot {\frac {d}{dt}}(\omega t)}$ Bring negative sign in front ${\displaystyle =-A\sin(\omega t)\omega }$ Evaluate remaining derivative ${\displaystyle v(t)=-\omega A\sin(\omega t).}$ Simplify.

The acceleration is then the second time derivative of position, or simply ${\displaystyle {\frac {dv}{dt}}}$ .

 ${\displaystyle a(t)={\frac {dv}{dt}}}$ Definition of acceleration in one dimension ${\displaystyle ={\frac {d}{dt}}{\bigl (}-\omega A\sin(\omega t){\bigr )}}$ Substitute ${\displaystyle v(t)}$ ${\displaystyle =-\omega A\cdot {\frac {d}{dt}}\sin(\omega t)}$ Bring constant term outside of derivative ${\displaystyle =-\omega A\cos(\omega t)\cdot {\frac {d}{dt}}(\omega t)}$ Differentiate outside function (sine) ${\displaystyle =-\omega A\cos(\omega t)\omega }$ Evaluate remaining derivative ${\displaystyle a(t)=-\omega ^{2}A\cos(\omega t).}$ Simplify.

From Newton's second law, ${\displaystyle {\vec {F}}=m{\vec {a}}}$ , where ${\displaystyle {\vec {F}}}$ is the net force and ${\displaystyle m}$ is the object's mass.

 ${\displaystyle {\vec {F}}=m{\vec {a}}}$ Newton's second law ${\displaystyle =m{\bigl (}-\omega ^{2}A\cos(\omega t){\bigr )}}$ Substitute ${\displaystyle a(t)}$ ${\displaystyle =-m\omega ^{2}A\cos(\omega t)}$ Simplify ${\displaystyle {\vec {F}}=-m\omega ^{2}x(t).}$ Substitute original ${\displaystyle x(t)}$ .

Thus it can be seen that these results are consistent with the observation that the force on a simple harmonic oscillator is a negative constant times the displacement.

## Chain Rule in Chemistry

The chain rule has many applications in Chemistry because many equations in Chemistry describe how one physical quantity depends on another, which in turn depends on another. For example, the ideal gas law describes the relationship between pressure, volume, temperature, and number of moles, all of which can also depend on time.

### Chemistry Example I: Ideal Gas Law

Isotherms of an ideal gas. The curved lines represent the relationship between pressure and volume for an ideal gas at different temperatures: lines which are further away from the origin (that is, lines that are nearer to the top right-hand corner of the diagram) represent higher temperatures.

Suppose a sample of ${\displaystyle n}$ moles of an ideal gas is held in an isothermal (constant temperature, ${\displaystyle T}$) chamber with initial volume ${\displaystyle V_{0}}$ . The ideal gas is compressed by a piston so that its volume changes at a constant rate so that ${\displaystyle V(t)=V_{0}-kt}$ , where ${\displaystyle t}$ is the time. The chain rule can be employed to find the time rate of change of the pressure.[3] The ideal gas law can be solved for the pressure, ${\displaystyle P}$ to give:

${\displaystyle P(t)={\frac {nRT}{V(t)}}}$

where ${\displaystyle P(t)}$ and ${\displaystyle V(t)}$ have been written as explicit functions of time and the other symbols are constant. Differentiating both sides yields

${\displaystyle {\frac {dP(t)}{dt}}=nRT\cdot {\frac {d}{dt}}\left({\frac {1}{V(t)}}\right)}$

where the constant terms, ${\displaystyle n}$ , ${\displaystyle R}$ , and ${\displaystyle T}$ , have been moved to the left of the derivative operator. Applying the chain rule gives

${\displaystyle {\frac {dP}{dt}}=nRT\cdot {\frac {d}{dV}}\left({\frac {1}{V(t)}}\right){\frac {dV}{dt}}=nRT\left(-{\frac {1}{V^{2}}}\right){\frac {dV}{dt}}}$

where the power rule has been used to differentiate ${\displaystyle {\frac {1}{V}}}$ , Since ${\displaystyle V(t)=V_{0}-kt}$ , ${\displaystyle {\frac {dV}{dt}}=-k}$ . Substituting in for ${\displaystyle V}$ and ${\displaystyle {\frac {dV}{dt}}}$ yields ${\displaystyle {\frac {dP}{dt}}}$ .

${\displaystyle {\frac {dP}{dt}}=-{\frac {nRTk}{(V_{0}-kt)^{2}}}}$

### Chemistry Example II: Kinetic Theory of Gases

The temperature of an ideal monatomic gas is a measure of the average kinetic energy of its atoms. The size of helium atoms relative to their spacing is shown to scale under 1950 atmospheres of pressure. The atoms have a certain, average speed, slowed down here two trillion fold from room temperature.

A second application of the chain rule in Chemistry is finding the rate of change of the average molecular speed, ${\displaystyle v}$ , in an ideal gas as the absolute temperature ${\displaystyle T}$ , increases at a constant rate so that ${\displaystyle T=T_{0}+at}$ , where ${\displaystyle T_{0}}$ is the initial temperature and ${\displaystyle t}$ is the time.[3] The kinetic theory of gases relates the root mean square of the molecular speed to the temperature, so that if ${\displaystyle v(t)}$ and ${\displaystyle T(t)}$ are functions of time,

${\displaystyle v(t)={\sqrt {\frac {3R\cdot T(t)}{M}}},}$

where ${\displaystyle R}$ is the ideal gas constant, and ${\displaystyle M}$ is the molecular weight.

Differentiating both sides with respect to time yields:

${\displaystyle {\frac {d}{dt}}v(t)={\frac {d}{dt}}\left({\sqrt {\frac {3R\cdot T(t)}{M}}}\right)}$

Using the chain rule to express the right side in terms of the with respect to temperature, ${\displaystyle T}$ , and time, ${\displaystyle t}$ , respectively gives

${\displaystyle {\frac {dv}{dt}}={\frac {d}{dT}}\left({\sqrt {\frac {3RT}{M}}}\right)\cdot {\frac {dT}{dt}}}$

Evaluating the derivative with respect to temperature, ${\displaystyle T}$ , yields

${\displaystyle {\frac {dv}{dt}}={\frac {1}{2}}{\sqrt {\frac {M}{3RT}}}\cdot {\frac {d}{dT}}\left({\frac {3RT}{M}}\right)\cdot {\frac {dT}{dt}}}$

Evaluating the remaining derivative with respect to ${\displaystyle T}$ , taking the reciprocal of the negative power, and substituting ${\displaystyle T=T_{0}+at}$ , produces

${\displaystyle {\frac {dv}{dt}}={\frac {1}{2}}{\sqrt {\frac {M}{3R(T_{0}+at)}}}\cdot {\frac {3R}{M}}\cdot {\frac {d}{dt}}\left(T_{0}+at\right)}$

Evaluating the derivative with respect to ${\displaystyle t}$ yields

${\displaystyle {\frac {dv}{dt}}={\frac {1}{2}}{\sqrt {\frac {M}{3R(T_{0}+at)}}}\cdot {\frac {3R}{M}}a}$

which simplifies to

${\displaystyle {\frac {dv}{dt}}={\frac {a}{2}}{\sqrt {\frac {3R}{M(T_{0}+at)}}}}$ .

## Proof of the chain rule

Suppose ${\displaystyle y}$ is a function of ${\displaystyle u}$ which is a function of ${\displaystyle x}$ (it is assumed that ${\displaystyle y}$ is differentiable at ${\displaystyle u}$ and ${\displaystyle x}$ , and ${\displaystyle u}$ is differentiable at ${\displaystyle x}$ . To prove the chain rule we use the definition of the derivative.

${\displaystyle {\frac {dy}{dx}}=\lim _{\Delta x\to 0}{\frac {\Delta y}{\Delta x}}}$

We now multiply ${\displaystyle {\frac {\Delta y}{\Delta x}}}$ by ${\displaystyle {\frac {\Delta u}{\Delta u}}}$ and perform some algebraic manipulation.

${\displaystyle \lim _{\Delta x\to 0}{\frac {\Delta y}{\Delta x}}=\lim _{\Delta x\to 0}{\frac {\Delta y}{\Delta u}}\cdot {\frac {\Delta u}{\Delta x}}=\lim _{\Delta x\to 0}{\frac {\Delta y}{\Delta u}}\cdot \lim _{\Delta x\to 0}{\frac {\Delta u}{\Delta x}}=\lim _{\Delta x\to 0}{\frac {\Delta y}{\Delta u}}\cdot {\frac {du}{dx}}}$

Note that as ${\displaystyle \Delta x}$ approaches ${\displaystyle 0}$ , ${\displaystyle \Delta u}$ also approaches ${\displaystyle 0}$ . So taking the limit as of a function as ${\displaystyle \Delta x}$ approaches ${\displaystyle 0}$ is the same as taking its limit as ${\displaystyle \Delta u}$ approaches ${\displaystyle 0}$ . Thus

${\displaystyle \lim _{\Delta x\to 0}{\frac {\Delta y}{\Delta u}}=\lim _{\Delta u\to 0}{\frac {\Delta y}{\Delta u}}={\frac {dy}{du}}}$

So we have

${\displaystyle {\frac {dy}{dx}}={\frac {dy}{du}}\cdot {\frac {du}{dx}}}$

## Exercises

1. Evaluate ${\displaystyle f'(x)}$ if ${\displaystyle f(x)=(x^{2}+5)^{2}}$ , first by expanding and differentiating directly, and then by applying the chain rule on ${\displaystyle f{\bigl (}u(x){\bigr )}=u^{2}}$ where ${\displaystyle u=x^{2}+5}$ . Compare answers.

${\displaystyle 4x^{3}+20x}$

2. Evaluate the derivative of ${\displaystyle y={\sqrt {1+x^{2}}}}$ using the chain rule by letting ${\displaystyle y={\sqrt {u}}}$ and ${\displaystyle u=1+x^{2}}$ .

${\displaystyle {\frac {x}{\sqrt {1+x^{2}}}}}$

Solutions

## References

1. http://www.math.brown.edu/help/derivtips.html
2. The derivative of ${\displaystyle e^{x}}$ is ${\displaystyle e^{x}}$ ; see Calculus/Derivatives of Exponential and Logarithm Functions.
3. a b University of British Columbia, UBC Calculus Online Course Notes, Applications of the Chain Rule, http://www.ugrad.math.ubc.ca/coursedoc/math100/notes/derivative/chainap.html Accessed 11/15/2010.