Section 12.1 The diff() Command
The
diff() command is probably the most basic way of finding the derivative of an expression. The first parameter is the expression to be differentiated and the second parameter is the variable that the expression is to be differentiated with respect to.
> diff(arctan(t), t);
\begin{equation*}
\displaystyle \frac{1}{{t}^{2}+1}
\end{equation*}
If you have assigned a function, then make sure to use proper function notation inside the
diff() command. As we will discover in Using Function Notation, there is simpler method for evaluating derivatives using function notation.
> f(x) := sin(x);
\begin{equation*}
\displaystyle f\, := \,x\mapsto \sin \left( x \right)
\end{equation*}
Make sure that you are taking the derivative with respect to the desired variable. Assigning a name to the derivative allows you to more easily substitute values into the derivative and determine the slope of a tangent line at a given point.
> deriv1 := diff(f(x), x);
\begin{equation*}
\displaystyle deriv1\, := \,\cos \left( x \right)
\end{equation*}
> slope := subs(x = Pi/2, deriv1); simplify(%);
\begin{equation*}
\displaystyle slope\, := \,\cos \left( \pi/2 \right)
\end{equation*}
\begin{equation*}
\displaystyle 0
\end{equation*}
Higher derivatives can be evaluated by applying the
diff() command multiple times in a row.
> diff(arctan(t), t); diff(%, t);
\begin{equation*}
\displaystyle \frac{1}{{t}^{2}+1}
\end{equation*}
\begin{equation*}
\displaystyle -\,{\frac {2t}{ \left( {t}^{2}+1 \right) ^{2}}}
\end{equation*}
Higher derivatives can also be calculated in a single command by specifying the variable repetitively or using the $ notation, as shown below.
Aside
> diff(f(x), x, x);
\begin{equation*}
\displaystyle -\sin \left( x \right)
\end{equation*}
> diff(f(x), x$2);
\begin{equation*}
\displaystyle -\sin \left( x \right)
\end{equation*}
