Next: Fitting Up: Functions Previous: Defining a Function

### Differentiating a Function

Functions in symbol manipulation systems such as Maxima, Maple and Mathematica are more like real mathematical functions and less like functions in Fortran or in C. In particular, because they are defined in terms of symbolic expressions, operations such as symbolic differentiation and integration can be performed on them.

Consider the following function:

where a and b are constants. Its derivative is:

In order to obtain this result with Maxima invoke Maxima command diff:

The second derivative of F(x) is

To obtain this result with Maxima you can either invoke diff on the result returned by the first diff, or invoke diff with three arguments, where the third argument is the order of the derivative:

Maxima also has a delayed  derivative, that is a diff operation, which marks an expression as a derivative, but doesn't evaluate it:

Here we have forced the evaluation by calling ev(%, diff), where diff is a special ev flag, that tells ev to perform all delayed differentiations in the expression, which is given as the first argument to ev. Maxima supports the following syntactic sugar notation that can be used instead of ev:

We can evaluate the value of dF/dx at a specific point x = 3, say, and for given values of constants a = 1 and b = 2as follows:

Now let us have a look at how all this works in Maple. First let us define function F:

Function diff works in Maple much the same as it does in Maxima. There is also a delayed evaluation version of diff, which is called Diff. Recall that a similar relationship between sum and Sum.

Higher order derivatives in Maple are done differently than in Maxima though. Calling diff(f(x), x, 2) would result in an error message. Instead you have to do this as follows:

Here we have also found the value of d2 F / d x2at x = 3 and for the values of constants a = 1 and b = 2.

In Mathematica the notation used in this context is painfully different for those who are used to Maxima and/or Maple, but, at the same time, somewhat closer to a traditional notation used in mathematics. The following listing shows a conversation with Mathematica, which begins with the definition of function F. This is followed by taking its derivative and then evaluation of its value at x=3 for a=1 and b=2.

Higher derivatives in Mathematica are calculated by replacing x in the call to D with a list, of which the first element is x and the second element is the order of the derivative:

This is somewhere in between Maxima and Maple notation.

Next: Fitting Up: Functions Previous: Defining a Function
Zdzislaw Meglicki
2001-02-26