# Wolfram Mathematica

## Evaluate a Derivative Using First Principles

Difference quotients can be used directly to compute not only the first derivative, but higher-order derivatives as well. Consider first the function g and its associated difference quotient.

In:= `g[x_] := x^2 Exp[x]`
In:= `dq1[x_] = DifferenceQuotient[g[x], {x, h}]`
Out= Taking the limit of the difference quotient gives the first derivative.

In:= `Limit[dq1[x], h -> 0]`
Out= In:= ```Limit[dq1[x], h -> 0]; Simplify[% == g'[x]]```
Out= The second derivative can be computed directly from the second difference quotient, without ever referencing the first derivative.

In:= `dq2[x_] = DifferenceQuotient[g[x], {x, 2, h}]`
Out= The limit as is the second derivative.

In:= `Limit[dq2[x], h -> 0]`
Out= In:= ```Limit[dq2[x], h -> 0]; Simplify[% == g''[x]]```
Out= The difference quotient of the first derivative is a different function from the second-order difference quotient of g, but its limit is also the second derivative.

In:= `dqp[x_] = DifferenceQuotient[g'[x], {x, h}]`
Out= In:= `Limit[dqp[x], h -> 0]`
Out= 