Example 18.5. Outputting the First \(n\) Derivatives.
We will use a basic ‘for’ loop to output the first \(10\) derivatives of the function \(f(x)=\sin(2x)\text{.}\) To do this, we will use the
diff() command within the loop. The ‘for’ loop will output the \(k\)th derivative, starting from \(k=1\) and ending at \(k=10\text{.}\)
Aside
> f(x) := sin(2*x);
\begin{equation*}
\displaystyle f\, := \,x\mapsto \sin \left( 2\,x \right)
\end{equation*}
> for k from 1 to 10 do
diff(f(x), x$k)
end do
\begin{equation*}
\displaystyle 2\,\cos \left( 2\,x \right)
\end{equation*}
\begin{equation*}
\displaystyle -4\,\sin \left( 2\,x \right)
\end{equation*}
\begin{equation*}
\displaystyle -8\,\cos \left( 2\,x \right)
\end{equation*}
\begin{equation*}
\displaystyle 16\,\sin \left( 2\,x \right)
\end{equation*}
\begin{equation*}
\displaystyle 32\,\cos \left( 2\,x \right)
\end{equation*}
\begin{equation*}
\displaystyle -64\,\sin \left( 2\,x \right)
\end{equation*}
\begin{equation*}
\displaystyle -128\,\cos \left( 2\,x \right)
\end{equation*}
\begin{equation*}
\displaystyle 256\,\sin \left( 2\,x \right)
\end{equation*}
\begin{equation*}
\displaystyle 512\,\cos \left( 2\,x \right)
\end{equation*}
\begin{equation*}
\displaystyle -1024\,\sin \left( 2\,x \right)
\end{equation*}
