Java Math Engine: Differentiation


Symbolic differentiation can be performed on objects known to the system such as built-in functions, previously defined functions, variable and operations.

The operator which performs symbolic differentiation is diff. There are three ways to use it:

  1. diff(expr, var, val)
  2. diff(expr, var)
  3. diff(expr)

In the above explanation, expr denotes a valid mathematical expression, var denotes the variable of differentiation and val denotes a value at which the derivative is evaluated.

Here are some examples:

  1. diff(sin(x^2),x,2) computes the derivative of sin(x^2) with respect to x at x=2.
  2. diff(sin(x^2),x) finds the derivative of sin(x^2) with respect to x.
  3. diff(sin(t)*exp(t),t) finds the derivative of sin(t)*exp(t) with respect to t.
  4. diff(ln(sin(x))) finds the derivative of ln(sin(x)) with respect to x.
  5. f(x)=diff((sin(x)+cos(x))/exp(x)) finds the derivative of (sin(x)+cos(x))/exp(x) with respect to x. It then assigns the result to f(x). f(x) can then be used as a new built-in function.
  6. diff(f(x),x) finds the derivative of f(x) with respect to x. For this to work, f(x) has to known to the system. If f(x) is as in example 5), then this line would compute the second derivative.
  7. diff(diff(x^3)) finds the second derivative of x^3 with respect to x. The expression being differentiated can itself contain diff.