Derivative calculator

Type a function and a point. The calculator gives the slope there with an error estimate and the tangent line, and says plainly when there is no derivative.

x² sin x at x = 1. Type any function and point; try abs(x) or floor(x) at 1 to see a refusal with its reason.

How the calculator finds a derivative

It applies the exact rules of differentiation (sum, product, quotient, power and chain rules, and the derivative of each function)[1] to the formula you type, and evaluates the result at a in double precision, with a bound on the rounding error of that evaluation. It does not print the formula for f′, only its value. As an independent check it also computes symmetric difference quotients (f(a + h) − f(a − h))/2h for a shrinking sequence of steps h and extrapolates them to h = 0 by Ridders’ method[2]; if the two disagree, the readout says the function wiggles on a scale finer than the steps (try x + 0.00001*sin(100000x)). Plugging in one tiny h does not work: below about 10−5 the computer’s rounding swamps the quotient[3]. “Show the work” lists the plain quotients, so you can watch them improve and then degrade.

A worked example

The default is f(x) = x² sin x at x = 1. By the product rule, f′(x) = 2x sin x + x² cos x, so f′(1) = 2 sin 1 + cos 1 ≈ 1.68294 + 0.54030 = 2.22324. The calculator prints 2.223244275484, the same number to all twelve digits shown. The tangent line through (1, sin 1) with that slope is y = 0.8415 + 2.2232(x − 1).

When it says there is no derivative

Where the rules do not apply at a, it measures the slope from the left and from the right separately, numerically, and refuses, saying why, in four situations:

  • a corner, where the two one-sided slopes differ: |x| at 0 has slopes −1 and +1;
  • a jump: floor(x) at 1, where the quotient from the left grows without bound and the right side is flat;
  • a vertical tangent or cusp, where the slope grows without bound: x^(1/3) at 0;
  • a point at the edge of the domain: asin(x) at 1, sqrt(x) at 0, ln(x) at 0.

It is a numerical instrument with stated limits. It works in double-precision arithmetic, about 16 significant digits, and the error bound tracks the rounding of every intermediate number: in sin(x + 52680931) the argument is rounded to about 10−8, and the bound grows to match. The number box takes the point exactly as typed, for example 1.5708 for a point just short of π/2; the slider moves in steps of 0.01.

Typing functions

Write products with or without * (x^2 sin(x)), powers with ^, and use sqrt, abs or |x|, exp or e^x, ln, log10, sin, cos, tan, asin, acos, atan, floor and sign, with pi and e as constants.

Sources

  1. Gilbert Strang and Edwin “Jed” Herman (2016). Calculus Volume 1. OpenStax, Rice University. textbook Free, peer-reviewed. Used here: §2.2 The Limit of a Function, §2.5 The Precise Definition of a Limit, §3.1 Defining the Derivative, §3.2 The Derivative as a Function, §3.3 Differentiation Rules, §3.6 The Chain Rule, §4.1 Related Rates, §5.1 Approximating Areas, §5.2 The Definite Integral, §5.3 The Fundamental Theorem of Calculus.
  2. C. J. F. Ridders (1982). Accurate computation of F′(x) and F′(x)F″(x). Advances in Engineering Software 4(2), 75–76. doi:10.1016/S0141-1195(82)80057-0. primary
  3. James Demmel (2002). Math 128a lecture notes: numerical differentiation. University of California, Berkeley. institutional