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[1]:=
![Click for copyable input](assets.en/evaluate-a-derivative-using-first-principles/In_28.png)
g[x_] := x^2 Exp[x]
In[2]:=
![Click for copyable input](assets.en/evaluate-a-derivative-using-first-principles/In_29.png)
dq1[x_] = DifferenceQuotient[g[x], {x, h}]
Out[2]=
![](assets.en/evaluate-a-derivative-using-first-principles/O_26.png)
Taking the limit of the difference quotient gives the first derivative.
In[3]:=
![Click for copyable input](assets.en/evaluate-a-derivative-using-first-principles/In_30.png)
Limit[dq1[x], h -> 0]
Out[3]=
![](assets.en/evaluate-a-derivative-using-first-principles/O_27.png)
In[4]:=
![Click for copyable input](assets.en/evaluate-a-derivative-using-first-principles/In_31.png)
Limit[dq1[x], h -> 0];
Simplify[% == g'[x]]
Out[4]=
![](assets.en/evaluate-a-derivative-using-first-principles/O_28.png)
The second derivative can be computed directly from the second difference quotient, without ever referencing the first derivative.
In[5]:=
![Click for copyable input](assets.en/evaluate-a-derivative-using-first-principles/In_32.png)
dq2[x_] = DifferenceQuotient[g[x], {x, 2, h}]
Out[5]=
![](assets.en/evaluate-a-derivative-using-first-principles/O_29.png)
The limit as is the second derivative.
In[6]:=
![Click for copyable input](assets.en/evaluate-a-derivative-using-first-principles/In_33.png)
Limit[dq2[x], h -> 0]
Out[6]=
![](assets.en/evaluate-a-derivative-using-first-principles/O_30.png)
In[7]:=
![Click for copyable input](assets.en/evaluate-a-derivative-using-first-principles/In_34.png)
Limit[dq2[x], h -> 0];
Simplify[% == g''[x]]
Out[7]=
![](assets.en/evaluate-a-derivative-using-first-principles/O_31.png)
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[8]:=
![Click for copyable input](assets.en/evaluate-a-derivative-using-first-principles/In_35.png)
dqp[x_] = DifferenceQuotient[g'[x], {x, h}]
Out[8]=
![](assets.en/evaluate-a-derivative-using-first-principles/O_32.png)
In[9]:=
![Click for copyable input](assets.en/evaluate-a-derivative-using-first-principles/In_36.png)
Limit[dqp[x], h -> 0]
Out[9]=
![](assets.en/evaluate-a-derivative-using-first-principles/O_33.png)