 Error, non-algebraic expressions cannot be differentiated - Maple Help

Home : Support : Online Help : Error, non-algebraic expressions cannot be differentiated

Error, non-algebraic expressions cannot be differentiated Description This error occurs when an argument that is not of type algebraic is passed to the diff command. Examples

Example 1

In

 > $\mathrm{diff}\left(x\to {x}^{2},x\right)$

Solution 1: Use an expression, not function, for the first argument:

 > $\mathrm{diff}\left({x}^{2},x\right)$
 ${2}{}{x}$ (2.1)

Solution 2: The differential operator D can differentiate procedures (including functional operators).

 > $\mathrm{D}\left(x\to {x}^{2}\right)$
 ${x}{↦}{2}{\cdot }{x}$ (2.2)

For users of Maple 2017 and earlier versions:  Previously, this error was generated in the following cases.  As a result of updates made in Maple 2018, these examples no longer result in an error.

Example 2

In the following example, an error is generated when a Vector, $v$, is passed to the diff command.

 > > $\mathrm{diff}\left(v,t\right)$

This is as expected since $v$ is not of type algebraic.

 > $\mathrm{type}\left(v,\mathrm{algebraic}\right)$
 ${\mathrm{false}}$ (2.3)

Solution:

Here, we assume that the intention was to differentiate each element of the Vector.  Since each element in the Vector is an algebraic expression, differentiating element-wise corrects the above error.  Specifically, use ~ to differentiate each element of the Vector.  For more information on ~, see the operators/elementwise help page.

 > $\mathrm{diff}~\left(v,t\right)$ > $\mathrm{type}\left(v\left[1\right],\mathrm{algebraic}\right),\mathrm{type}\left(v\left[2\right],\mathrm{algebraic}\right)$
 ${\mathrm{true}}{,}{\mathrm{true}}$ (2.4)

Example 3

In the following example, the call to the VectorCalculus package has been omitted.  This results in the top-level diff function being used for the right-hand side values of $\mathrm{r1}$ and $\mathrm{r2}$, rather than VectorCalculus[diff].  Since the top-level diff function does not accept Vectors as arguments, an error occurs.

 > $x≔\left(r,t\right)\to r\cdot \mathrm{sin}\left(t\right)$
 ${x}{:=}\left({r}{,}{t}\right){→}{r}{}{\mathrm{sin}}{}\left({t}\right)$ (2.5)
 > $y≔\left(r,t\right)\to r\cdot \mathrm{cos}\left(t\right)$
 ${y}{:=}\left({r}{,}{t}\right){→}{r}{}{\mathrm{cos}}{}\left({t}\right)$ (2.6)
 > $z≔\left(r,t\right)\to {r}^{2}\cdot \mathrm{sin}\left(t\right)\cdot \mathrm{cos}\left(t\right)$
 ${z}{:=}\left({r}{,}{t}\right){→}{{r}}^{{2}}{}{\mathrm{sin}}{}\left({t}\right){}{\mathrm{cos}}{}\left({t}\right)$ (2.7)
 > $R≔\left(r,t\right)\to ⟨x\left(r,t\right),y\left(r,t\right),z\left(r,t\right)⟩$
 ${R}{:=}\left({r}{,}{t}\right){→}⟨{x}{}\left({r}{,}{t}\right){,}{y}{}\left({r}{,}{t}\right){,}{z}{}\left({r}{,}{t}\right)⟩$ (2.8)
 > $R\left(r,t\right);$ > $\mathrm{r1}≔\mathrm{diff}\left(R\left(r,t\right),r\right)$
 > $\mathrm{r2}≔\mathrm{diff}\left(R\left(r,t\right),t\right)$

Solution:

Adding with(VectorCalculus) before the sequence of statements results in VectorCalculus[diff]. This corrects the error.

 > $\mathrm{with}\left(\mathrm{VectorCalculus}\right):$
 > $x≔\left(r,t\right)\to r\cdot \mathrm{sin}\left(t\right)$
 ${x}{:=}\left({r}{,}{t}\right){→}{r}{}{\mathrm{sin}}{}\left({t}\right)$ (2.9)
 > $y≔\left(r,t\right)\to r\cdot \mathrm{cos}\left(t\right)$
 ${y}{:=}\left({r}{,}{t}\right){→}{r}{}{\mathrm{cos}}{}\left({t}\right)$ (2.10)
 > $z≔\left(r,t\right)\to {r}^{2}\cdot \mathrm{sin}\left(t\right)\cdot \mathrm{cos}\left(t\right)$
 ${z}{:=}\left({r}{,}{t}\right){→}{{r}}^{{2}}{}{\mathrm{sin}}{}\left({t}\right){}{\mathrm{cos}}{}\left({t}\right)$ (2.11)
 > $R≔\left(r,t\right)\to ⟨x\left(r,t\right),y\left(r,t\right),z\left(r,t\right)⟩$
 ${R}{:=}\left({r}{,}{t}\right){→}{\mathrm{VectorCalculus}}{:-}{\mathrm{<,>}}{}\left({x}{}\left({r}{,}{t}\right){,}{y}{}\left({r}{,}{t}\right){,}{z}{}\left({r}{,}{t}\right)\right)$ (2.12)
 > $R\left(r,t\right);$ > $\mathrm{r1}≔\mathrm{diff}\left(R\left(r,t\right),r\right)$ > $\mathrm{r2}≔\mathrm{diff}\left(R\left(r,t\right),t\right)$ 