Skip to contentSkip to lesson map

Derivatives of Basic Functions

Status
Updates coming
Reading
MMAC Ch 4.3, pp 388-399 and 402-403
Lesson map

Objectives

  1. Use the 1st and 2nd derivatives to characterize a function (increasing/decreasing, local extrema, concavity, inflection points).
  2. Find derivatives of basic power functions using the power rule, by hand.
  3. Find derivatives of basic modeling functions by hand (exponential, sinusoidal, logarithmic, etc.).
  4. Compute derivatives of linear combinations using the constant, constant-multiple, and sum/difference rules.
  5. In R, use D() to find the derivative of a function.

1. Characterizing a Function

Objective. Use the 1st and 2nd derivatives to characterize a function (increasing/decreasing, local extrema, concavity, inflection points).

Intervals of increase and decrease, local extrema, concavity, and points of inflection are read from the graphs of f′f' and f′′f'' in sections 3 and 4 of the Lesson 28 Notes. With formulas for f′f' and f′′f'', the same intervals and points are found by algebra.

On an interval where f′f' is defined, continuous, and never zero, f′f' has one sign. As a result, the sign of f′f' at a single test input in such an interval is the sign of f′f' on the whole interval. The same is true of f′′f''.

Characterizing a function from f′f' and f′′f''.

  1. Find the inputs where f′(x)=0f'(x) = 0 or where f′(x)f'(x) does not exist, and evaluate f′f' at one test input in each interval those inputs mark off. The function ff is increasing on an interval with a positive test value and decreasing on an interval with a negative test value.
  2. At each input where ff is continuous, report a local maximum where f′f' changes from positive to negative and a local minimum where f′f' changes from negative to positive. Substitute each such input into f(x)f(x) for the value.
  3. Find the inputs where f′′(x)=0f''(x) = 0 or where f′′(x)f''(x) does not exist, and evaluate f′′f'' at one test input in each interval those inputs mark off. The function ff is concave up on an interval with a positive test value and concave down on an interval with a negative test value.
  4. Report a point of inflection (c,f(c))(c, f(c)) at each input cc where the sign of f′′f'' changes and ff is continuous.

Examples 1 and 2 give f′f' and f′′f'' in the stem. The rules for finding them from a formula for ff are in sections 2 to 4.

Example 1

The function

f(x)=x3−3x2−9x+5 f(x) = x^3 - 3x^2 - 9x + 5

has first and second derivatives

f′(x)=3(x+1)(x−3),f′′(x)=6(x−1). f'(x) = 3(x + 1)(x - 3), \qquad f''(x) = 6(x - 1).

Determine where ff is increasing and decreasing, its local extrema, its concavity, and its points of inflection.

ShowHide solution

Because the derivative f′f' exists at every input, ff is continuous everywhere. By the sign test for local extrema (Lesson 28 Notes, section 3), ff has a local extremum at each input where the sign of f′f' changes. The factors of f′f' are zero at x=−1x = -1 and x=3x = 3. Evaluate f′f' at one input in each interval those inputs mark off:

f′(−2)=3(−1)(−5)=15>0,f′(0)=3(1)(−3)=−9<0,f′(4)=3(5)(1)=15>0. f'(-2) = 3(-1)(-5) = 15 > 0, \qquad f'(0) = 3(1)(-3) = -9 < 0, \qquad f'(4) = 3(5)(1) = 15 > 0.

The function ff is increasing for x<−1x < -1 and for x>3x > 3, and decreasing for −1<x<3-1 < x < 3. Because f′f' changes from positive to negative at x=−1x = -1 and from negative to positive at x=3x = 3, ff has a local maximum at x=−1x = -1 and a local minimum at x=3x = 3. Substitute each input into f(x)f(x) for the values:

f(−1)=(−1)3−3(−1)2−9(−1)+5=−1−3+9+5=10,f(3)=33−3(3)2−9(3)+5=27−27−27+5=−22.\begin{align*} f(-1) &= (-1)^3 - 3(-1)^2 - 9(-1) + 5 = -1 - 3 + 9 + 5 = 10,\\ f(3) &= 3^3 - 3(3)^2 - 9(3) + 5 = 27 - 27 - 27 + 5 = -22. \end{align*}

The second derivative is zero at x=1x = 1. Evaluate f′′f'' at one input on each side:

f′′(0)=6(0−1)=−6<0,f′′(2)=6(2−1)=6>0. f''(0) = 6(0 - 1) = -6 < 0, \qquad f''(2) = 6(2 - 1) = 6 > 0.

The function ff is concave down for x<1x < 1 and concave up for x>1x > 1. Because f′′f'' changes sign at x=1x = 1, the point (1,f(1))(1, f(1)) is a point of inflection, with

f(1)=13−3(1)2−9(1)+5=1−3−9+5=−6. f(1) = 1^3 - 3(1)^2 - 9(1) + 5 = 1 - 3 - 9 + 5 = -6.

On the graph of ff, the local maximum f(−1)=10f(-1) = 10 is the height of the peak at (−1,10)(-1, 10), and the local minimum f(3)=−22f(3) = -22 is the height of the valley at (3,−22)(3, -22). At the point of inflection (1,−6)(1, -6), the graph changes from concave down to concave up.

Figure

Example 2

The function

g(x)=x4−4x3 g(x) = x^4 - 4x^3

has first and second derivatives

g′(x)=4x2(x−3),g′′(x)=12x(x−2). g'(x) = 4x^2(x - 3), \qquad g''(x) = 12x(x - 2).

Determine where gg is increasing and decreasing, its local extrema, its concavity, and its points of inflection.

ShowHide solution

The factors of g′g' are zero at x=0x = 0 and x=3x = 3. Evaluate g′g' at one input in each interval those inputs mark off:

g′(−1)=4(1)(−4)=−16<0,g′(1)=4(1)(−2)=−8<0,g′(4)=4(16)(1)=64>0. g'(-1) = 4(1)(-4) = -16 < 0, \qquad g'(1) = 4(1)(-2) = -8 < 0, \qquad g'(4) = 4(16)(1) = 64 > 0.

Thus, gg is decreasing for x<0x < 0 and for 0<x<30 < x < 3, and increasing for x>3x > 3. The polynomial gg is continuous everywhere. Because g′g' is negative on both sides of x=0x = 0, gg has no local extremum at x=0x = 0. The sign of g′g' changes from negative to positive at x=3x = 3. By the sign test for local extrema, gg has a local minimum there:

g(3)=34−4(3)3=81−108=−27. g(3) = 3^4 - 4(3)^3 = 81 - 108 = -27.

The factors of g′′g'' are zero at x=0x = 0 and x=2x = 2. Evaluate g′′g'' at one input in each interval:

g′′(−1)=12(−1)(−3)=36>0,g′′(1)=12(1)(−1)=−12<0,g′′(3)=12(3)(1)=36>0. g''(-1) = 12(-1)(-3) = 36 > 0, \qquad g''(1) = 12(1)(-1) = -12 < 0, \qquad g''(3) = 12(3)(1) = 36 > 0.

The function gg is concave up for x<0x < 0 and for x>2x > 2, and concave down for 0<x<20 < x < 2. The concavity changes at both inputs, and the points of inflection are (0,g(0))(0, g(0)) and (2,g(2))(2, g(2)), with

g(0)=04−4(0)3=0,g(2)=24−4(2)3=16−32=−16. g(0) = 0^4 - 4(0)^3 = 0, \qquad g(2) = 2^4 - 4(2)^3 = 16 - 32 = -16.

On the graph of gg, the tangent line at (0,0)(0, 0) is horizontal, yet gg keeps decreasing to the local minimum g(3)=−27g(3) = -27 at (3,−27)(3, -27). The concavity changes at (0,0)(0, 0) and (2,−16)(2, -16).

Figure

Lesson map

2. The Power Rule

Objective. Find derivatives of basic power functions using the power rule, by hand.

Rule 1 (Constant rule).

For every real number cc, the derivative of the constant function cc is 0,

ddx[c]=0. \frac{d}{dx}[c] = 0.

For constants mm and bb, the derivative of the linear function mx+bmx + b is its slope, ddx[mx+b]=m\frac{d}{dx}[mx + b] = m, because the tangent line to a line at every input is the line itself.

Rule 2 (Power rule).

For every real number nn,

ddx[xn]=nxn−1 \frac{d}{dx}[x^n] = nx^{n-1}

for every xx with x>0x > 0, for every xx when nn is a positive integer, and for every xx with x≠0x \neq 0 when nn is a negative integer.

Why it works: the power rule for a positive integer nn

For a positive integer nn, every pair of numbers aa and bb satisfies the factoring

an−bn=(a−b)(an−1+an−2b+⋯+bn−1). a^n - b^n = (a - b)\left(a^{n-1} + a^{n-2}b + \dots + b^{n-1}\right).

Substitute a=x+ha = x + h and b=xb = x into the factoring. The quotient in the limit definition of the derivative (Lesson 26 Notes, section 4) becomes

(x+h)n−xnh=(x+h)n−1+(x+h)n−2x+⋯+xn−1 \frac{(x + h)^n - x^n}{h} = (x + h)^{n-1} + (x + h)^{n-2}x + \dots + x^{n-1}

for h≠0h \neq 0. The right side has nn terms, and each approaches xn−1x^{n-1} as h→0h \to 0. The limit is therefore nxn−1nx^{n-1}. For other nn the rule can fail at x=0x = 0. For example, the function x=x1/2\sqrt{x} = x^{1/2} has no derivative at 0, and the formula 12x−1/2\tfrac{1}{2}x^{-1/2} gives no value there.

Rewriting as a power. The power rule applies to xnx^n only. Before the power rule is applied, a root becomes a power with a fractional exponent, and 1 over a power becomes a power with a negative exponent. For integers pp and qq with q>0q > 0, and every real number nn,

xpq=xp/q for x>0,1xn=x−n for x>0. \sqrt[q]{x^p} = x^{p/q} \ \text{for } x > 0, \qquad \frac{1}{x^n} = x^{-n} \ \text{for } x > 0.

When nn is an integer, the second rewrite is true for every xx with x≠0x \neq 0. Combine a product or quotient of powers of xx into one power first: add the exponents of factors that multiply, and subtract the exponent of a factor that divides. The power rule applies to the single power that results.

Example 3

Find the derivatives:

1x5,x3,1x35. \frac{1}{x^5}, \qquad \sqrt{x^3}, \qquad \frac{1}{\sqrt[5]{x^3}}.
ShowHide solution

Rewrite each function as a power xnx^n, then apply the power rule ddx[xn]=nxn−1\frac{d}{dx}[x^n] = nx^{n-1}.

The first function, 1 over a power, becomes a power with a negative exponent, 1x5=x−5\frac{1}{x^5} = x^{-5}:

ddx[x−5]=−5x−5−1=−5x−6=−5x6 \frac{d}{dx}\left[x^{-5}\right] = -5x^{-5 - 1} = -5x^{-6} = -\frac{5}{x^6}

for every xx with x≠0x \neq 0. The rewrite is true for these inputs because the exponent −5-5 is an integer.

The root in the second function becomes a power with a fractional exponent, x3=x3/2\sqrt{x^3} = x^{3/2}:

ddx[x3/2]=32x3/2−1=32x1/2 \frac{d}{dx}\left[x^{3/2}\right] = \frac{3}{2}x^{3/2 - 1} = \frac{3}{2}x^{1/2}

for every xx with x>0x > 0. The rewriting lead gives the rewrite for these inputs.

Apply both rewrites to the third function. The root is x35=x3/5\sqrt[5]{x^3} = x^{3/5}, and 1 over that power becomes a power with a negative exponent, 1x35=x−3/5\frac{1}{\sqrt[5]{x^3}} = x^{-3/5}:

ddx[x−3/5]=−35x−3/5−1=−35x−8/5 \frac{d}{dx}\left[x^{-3/5}\right] = -\frac{3}{5}x^{-3/5 - 1} = -\frac{3}{5}x^{-8/5}

for every xx with x>0x > 0. The rewriting lead gives both rewrites for these inputs.

Example 4

Find the derivative:

x4x3x2. \frac{x^4\sqrt[3]{x}}{x^2}.
ShowHide solution

Write the root as x3=x1/3\sqrt[3]{x} = x^{1/3} and combine the exponents into one power:

x4x3x2=x4x1/3x2=x4+1/3−2=x7/3. \frac{x^4\sqrt[3]{x}}{x^2} = \frac{x^4 x^{1/3}}{x^2} = x^{4 + 1/3 - 2} = x^{7/3}.

Apply the power rule:

ddx[x7/3]=73x7/3−1=73x4/3 \frac{d}{dx}\left[x^{7/3}\right] = \frac{7}{3}x^{7/3 - 1} = \frac{7}{3}x^{4/3}

for every xx with x>0x > 0. The rewriting lead gives the rewrites for these inputs.

The words estimate and find. “Estimate f′(a)f'(a)” asks for the average rate of change over a short interval. “Find” or “compute” f′(a)f'(a) asks for the value of the derivative itself, from a derivative rule by hand or from D() in R.

Example 5

For the function

f(x)=1x3, f(x) = \frac{1}{x^3},

estimate f′(2)f'(2) with an interval of width 0.001, then compute f′(2)f'(2) exactly.

ShowHide solution

Estimate f′(2)f'(2) with the average rate of change from 2 to 2.001:

f′(2)≈f(2.001)−f(2)0.001=12.0013−1230.001≈0.124813−0.1250.001≈−0.187. f'(2) \approx \frac{f(2.001) - f(2)}{0.001} = \frac{\frac{1}{2.001^3} - \frac{1}{2^3}}{0.001} \approx \frac{0.124813 - 0.125}{0.001} \approx -0.187.

Rewrite f(x)=x−3f(x) = x^{-3} and apply the power rule for the exact value:

f′(x)=−3x−3−1=−3x−4sof′(2)=−3(2)−4=−316=−0.1875. f'(x) = -3x^{-3 - 1} = -3x^{-4} \quad\text{so}\quad f'(2) = -3(2)^{-4} = -\frac{3}{16} = -0.1875.

The estimate is within 0.001 of the exact value. The exact value is the slope of the tangent line to the graph of ff at (2,f(2))=(2,0.125)(2, f(2)) = (2, 0.125), and the estimate is the slope of a secant line close to it.

Figure

Lesson map

3. Basic Modeling Functions

Objective. Find derivatives of basic modeling functions by hand (exponential, sinusoidal, logarithmic, etc.).

Definition 3 (Basic modeling functions).

The basic modeling functions are the simplest forms of the modeling functions. For constants mm, bb, and nn and a constant aa with a>0a > 0, they are

mx+b,xn,ex,ax,ln⁡(x),sin⁡(x),cos⁡(x). mx + b, \qquad x^n, \qquad e^x, \qquad a^x, \qquad \ln(x), \qquad \sin(x), \qquad \cos(x).

The function exsin⁡(x)e^x\sin(x) is not a basic modeling function, because it multiplies two basic modeling functions together and is none of the forms in the definition. Lesson 30 differentiates products.

The sine and cosine rules below hold for xx in radians, the textbook’s unit for angles.

Rule 4 (Derivatives of basic modeling functions).

For a constant aa with a>0a > 0 and constants mm and bb, the basic modeling functions have these derivatives:

Exponential rule:ddx[ex]=ex,ddx[ax]=axln⁡(a),Extended exponential rule:ddx[emx+b]=memx+b,Logarithm rule:ddx[ln⁡(x)]=1x for x>0,Sine and cosine rules:ddx[sin⁡(x)]=cos⁡(x),ddx[cos⁡(x)]=−sin⁡(x). \begin{array}{ll} \text{Exponential rule:} & \frac{d}{dx}[e^x] = e^x, \qquad \frac{d}{dx}[a^x] = a^x\ln(a), \\[6pt] \text{Extended exponential rule:} & \frac{d}{dx}[e^{mx + b}] = me^{mx + b}, \\[6pt] \text{Logarithm rule:} & \frac{d}{dx}[\ln(x)] = \dfrac{1}{x} \text{ for } x > 0, \\[6pt] \text{Sine and cosine rules:} & \frac{d}{dx}[\sin(x)] = \cos(x), \qquad \frac{d}{dx}[\cos(x)] = -\sin(x). \end{array}

Linear exponent. The extended exponential rule applies when the exponent is linear in xx. Differentiating ex2e^{x^2} or ecos⁡(x)e^{\cos(x)}, where the exponent is not linear, takes the chain rule (Lesson 32).

Power or exponential. In a power function the variable is the base, as in x3x^3, and the power rule applies. In an exponential function the variable is the exponent, as in 3x3^x, and the exponential rule ddx[ax]=axln⁡(a)\frac{d}{dx}[a^x] = a^x\ln(a) applies. Thus ddx[x3]=3x2\frac{d}{dx}[x^3] = 3x^2 and ddx[3x]=3xln⁡(3)\frac{d}{dx}[3^x] = 3^x\ln(3).

Constant expressions. An expression with no xx in it, such as cos⁡(4)\cos(4), ln⁡(6)\ln(6), e2e^2, or π\pi, is a constant with derivative 0.

Example 6

Find the derivatives:

7x,x7,e3x−2,cos⁡(x),ln⁡(2). 7^x, \qquad x^7, \qquad e^{3x - 2}, \qquad \cos(x), \qquad \ln(2).
ShowHide solution
  • By the exponential rule, ddx[7x]=7xln⁡(7)\frac{d}{dx}[7^x] = 7^x\ln(7).
  • By the power rule, ddx[x7]=7x6\frac{d}{dx}[x^7] = 7x^6.
  • By the extended exponential rule with m=3m = 3, ddx[e3x−2]=3e3x−2\frac{d}{dx}[e^{3x - 2}] = 3e^{3x - 2}.
  • By the cosine rule, ddx[cos⁡(x)]=−sin⁡(x)\frac{d}{dx}[\cos(x)] = -\sin(x).
  • Because ln⁡(2)\ln(2) is a constant, ddx[ln⁡(2)]=0\frac{d}{dx}[\ln(2)] = 0.

Example 7

Find each derivative and evaluate it at the given input:

ln⁡(x) at x=4,sin⁡(x) at x=π3,2x at x=3. \ln(x) \text{ at } x = 4, \qquad \sin(x) \text{ at } x = \frac{\pi}{3}, \qquad 2^x \text{ at } x = 3.
ShowHide solution
  • By the logarithm rule, ddx[ln⁡(x)]=1x\frac{d}{dx}[\ln(x)] = \dfrac{1}{x}. At x=4x = 4 the derivative is 14=0.25\dfrac{1}{4} = 0.25.
  • By the sine rule, ddx[sin⁡(x)]=cos⁡(x)\frac{d}{dx}[\sin(x)] = \cos(x). At x=π3x = \frac{\pi}{3} the derivative is cos⁡ ⁣(π3)=0.5\cos\!\left(\frac{\pi}{3}\right) = 0.5.
  • By the exponential rule, ddx[2x]=2xln⁡(2)\frac{d}{dx}[2^x] = 2^x\ln(2). At x=3x = 3 the derivative is 23ln⁡(2)=8ln⁡(2)≈5.5452^3\ln(2) = 8\ln(2) \approx 5.545.

Example 8

Determine which of these functions are differentiated with the power rule:

x4,4x,1x4,e4x,ln⁡(x). x^4, \qquad 4^x, \qquad \frac{1}{x^4}, \qquad e^{4x}, \qquad \ln(x).
ShowHide solution

The functions x4x^4 and 1/x4=x−41/x^4 = x^{-4} are differentiated with the power rule, because in each the variable is the base and the exponent is a constant. The function 4x4^x is differentiated with the exponential rule, because the variable is the exponent. The function e4xe^{4x} is differentiated with the extended exponential rule, because its exponent 4x4x is linear in xx. The function ln⁡(x)\ln(x) is differentiated with the logarithm rule, because it is the natural logarithm.

Lesson map

4. Linear Combinations

Objective. Compute derivatives of linear combinations using the constant, constant-multiple, and sum/difference rules.

Rule 5 (Constant multiple rule).

For a real number kk and a differentiable function f(x)f(x),

ddx[k f(x)]=k f′(x). \frac{d}{dx}[k\,f(x)] = k\,f'(x).

Rule 6 (Sum and difference rules).

For differentiable functions f(x)f(x) and g(x)g(x),

ddx[f(x)±g(x)]=f′(x)±g′(x). \frac{d}{dx}[f(x) \pm g(x)] = f'(x) \pm g'(x).

Definition 7 (Linear combination).

A linear combination of functions is a sum of constant multiples of the functions, such as 3f(x)−2g(x)3f(x) - 2g(x).

The function x2sin⁡(x)x^2\sin(x) is not a linear combination of x2x^2 and sin⁡(x)\sin(x), because it is a product of the two functions, and the definition allows only a sum of constant multiples. Products are differentiated in Lesson 30.

With the constant multiple rule and the sum and difference rules, a linear combination is differentiated one term at a time. A constant term has derivative 0 by the constant rule (section 2).

Example 9

Find f′(x)f'(x):

f(x)=5x4−3x+6sin⁡(x)+cos⁡(2)−4ln⁡(x)+2x. f(x) = 5x^4 - \frac{3}{x} + 6\sin(x) + \cos(2) - 4\ln(x) + 2^x.
ShowHide solution

Rewrite −3/x-3/x as −3x−1-3x^{-1}. By the definition of a linear combination, ff is a sum of constant multiples of x4x^4, x−1x^{-1}, sin⁡(x)\sin(x), ln⁡(x)\ln(x), 2x2^x, and the constant function 1. The term cos⁡(2)\cos(2) is a number times the constant function 1; the 3 in the Lesson 17 non-example 2bu‾+32\overline{\vphantom{b}u} + 3 is a scalar with no vector. Differentiate term by term with the constant multiple rule, the sum and difference rules, the power, sine, logarithm, and exponential rules, and the constant rule for cos⁡(2)\cos(2):

f′(x)=5(4x3)−3(−x−2)+6cos⁡(x)+0−4(1x)+2xln⁡(2)=20x3+3x2+6cos⁡(x)−4x+2xln⁡(2).\begin{align*} f'(x) &= 5(4x^3) - 3(-x^{-2}) + 6\cos(x) + 0 - 4\left(\frac{1}{x}\right) + 2^x\ln(2)\\ &= 20x^3 + \frac{3}{x^2} + 6\cos(x) - \frac{4}{x} + 2^x\ln(2). \end{align*}

Example 10

Name the rules needed to differentiate hh, then find h′(x)h'(x):

h(x)=14x2+ex. h(x) = \frac{1}{4x^2} + e^x.
ShowHide solution

Rewrite the first term as a constant times a power:

14x2=14⋅1x2=14x−2. \frac{1}{4x^2} = \frac{1}{4} \cdot \frac{1}{x^2} = \frac{1}{4}x^{-2}.

The rules needed are the constant multiple rule, the power rule, the sum and difference rules, and the exponential rule. Apply them term by term:

h′(x)=14(−2x−3)+ex=−12x−3+ex. h'(x) = \frac{1}{4}\left(-2x^{-3}\right) + e^x = -\frac{1}{2}x^{-3} + e^x.

Example 11

Find the first four derivatives of the function

f(x)=x3−5x. f(x) = x^3 - 5x.
ShowHide solution

Differentiate each derivative to get the next one:

f′(x)=3x2−5,f′′(x)=6x,f′′′(x)=6,f(4)(x)=0. f'(x) = 3x^2 - 5, \qquad f''(x) = 6x, \qquad f'''(x) = 6, \qquad f^{(4)}(x) = 0.

The third and fourth derivatives are written f′′′(x)f'''(x) and f(4)(x)f^{(4)}(x), the nnth-derivative notation of the Lesson 28 Notes, section 2.

Example 12

For a constant v0v_0 in meters per second and a constant pp in meters, a projectile’s height in meters tt seconds after launch is

h(t)=−4.9t2+v0t+p. h(t) = -4.9t^2 + v_0t + p.

Find the velocity h′(t)h'(t) and the acceleration h′′(t)h''(t), the rate of change of the velocity, with units.

ShowHide solution

By the constant multiple rule and the power rule, −4.9t2-4.9t^2 has derivative −4.9(2t)=−9.8t-4.9(2t) = -9.8t, and v0tv_0t has derivative v0(1)=v0v_0(1) = v_0. The constant pp has derivative 0:

h′(t)=−9.8t+v0. h'(t) = -9.8t + v_0.

Differentiate h′h' the same way. The term −9.8t-9.8t has derivative −9.8-9.8, and the constant v0v_0 has derivative 0:

h′′(t)=−9.8. h''(t) = -9.8.

The velocity h′(t)h'(t) is in meters per second, and the acceleration h′′(t)h''(t) is in meters per second per second.

Lesson map

5. Derivatives in R

Objective. In R, use D() to find the derivative of a function.

The command D(formula ~ x) differentiates the left side of the tilde with respect to xx and returns the derivative as a function. The left side is either an expression in xx or a stored function written as f(x).

A derivative stored under a name such as df is evaluated and plotted the same way as a function from makeFun.

To find the second derivative, write the variable twice after the tilde, as in d2f = D(f(x) ~ x & x).

The natural logarithm and exe^x in R. The natural logarithm is log(x), and exe^x is exp(x). A call to ln() gives an error:

> ln(2)
Error in ln(2) : could not find function "ln"

When exe^x is typed as e^ x, R treats the letter e as a second input of the derivative. Evaluating the derivative at one input then gives an error:

> de = D(e^ x ~ x)
> de(1)
Error in de(1) : argument "e" is missing, with no default

Example 13

For the function

f(x)=x3−5x, f(x) = x^3 - 5x,

find f′(x)f'(x), f′(0)f'(0), and f′′(1)f''(1) in R.

ShowHide solution

Differentiate the expression with D() to see f′(x)f'(x). Then store ff and its first and second derivatives, evaluate f′f' at x=0x = 0, and evaluate f′′f'' at x=1x = 1. Used R.

D(x^3 - 5*x ~ x)
function (x)
3 * x^2 - 5
f = makeFun(x^3 - 5*x ~ x)
df = D(f(x) ~ x)
df(0)
[1] -5
d2f = D(f(x) ~ x & x)
d2f(1)
[1] 6

R prints function (x) and then the body 3 * x^2 - 5, its spelling of f′(x)=3x2−5f'(x) = 3x^2 - 5. The calls df(0) and d2f(1) give f′(0)=−5f'(0) = -5 and f′′(1)=6f''(1) = 6. As a check by hand, f′(x)=3x2−5f'(x) = 3x^2 - 5 and f′′(x)=6xf''(x) = 6x give

f′(0)=3(0)2−5=−5,f′′(1)=6(1)=6. f'(0) = 3(0)^2 - 5 = -5, \qquad f''(1) = 6(1) = 6.

Example 14

For the function

g(x)=6ln⁡(x)−3ex, g(x) = 6\ln(x) - 3e^x,

find g′(1)g'(1) and g′′(1)g''(1) by hand, and check both in R.

ShowHide solution

The constant multiple rule, the difference rule, the logarithm rule, and the exponential rule give

g′(x)=6x−3exsog′(1)=61−3e1=6−3e≈−2.155. g'(x) = \frac{6}{x} - 3e^x \quad\text{so}\quad g'(1) = \frac{6}{1} - 3e^1 = 6 - 3e \approx -2.155.

Differentiating again, with 6x=6x−1\frac{6}{x} = 6x^{-1} and the power rule, gives

g′′(x)=−6x−2−3ex=−6x2−3exsog′′(1)=−6−3e≈−14.155. g''(x) = -6x^{-2} - 3e^x = -\frac{6}{x^2} - 3e^x \quad\text{so}\quad g''(1) = -6 - 3e \approx -14.155.

Check both values in R. The command D() returns g′g' and g′′g'' as functions, and evaluating them at 1 gives the values to more digits. Used R.

g = makeFun(6*log(x) - 3*exp(x) ~ x)
dg = D(g(x) ~ x)
dg(1)
[1] -2.154845
d2g = D(g(x) ~ x & x)
d2g(1)
[1] -14.15485

R’s values agree with the hand values g′(1)≈−2.155g'(1) \approx -2.155 and g′′(1)≈−14.155g''(1) \approx -14.155.

Example 15

Find q′(π)q'(\pi) in R:

q(x)=ln⁡(5)+3x4−ex+sin⁡(x). q(x) = \ln(5) + 3x^4 - e^x + \sin(x).
ShowHide solution

Differentiate qq with D() and evaluate the derivative at π\pi. Used R.

dq = D(log(5) + 3*x^4 - exp(x) + sin(x) ~ x)
dq(pi)
[1] 347.9346

Therefore q′(π)≈347.935q'(\pi) \approx 347.935. As a check, the derivative by hand, q′(x)=12x3−ex+cos⁡(x)q'(x) = 12x^3 - e^x + \cos(x), gives 12π3−eπ+cos⁡(π)≈347.93512\pi^3 - e^{\pi} + \cos(\pi) \approx 347.935.

Lesson map

Found a mistake, a broken tool or something unclear? Report a problem