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:
- diff(expr, var, val)
- diff(expr, var)
- 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.
- The first form computes the derivative of expr with
respect to var, and evaluates it at val.
- The second form performs symbolic differentiation with respect to var.
The answer it gives is a function.
- The third form is similar to the second form, it assumes that the variable
of differentiation is x.
Here are some examples:
- diff(sin(x^2),x,2) computes the derivative of
sin(x^2) with respect to x
at x=2.
- diff(sin(x^2),x) finds the derivative of sin(x^2)
with respect to x.
- diff(sin(t)*exp(t),t) finds the derivative of
sin(t)*exp(t) with respect to t.
- diff(ln(sin(x))) finds the derivative of ln(sin(x))
with respect to x.
- 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.
- 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.
- diff(diff(x^3)) finds the second derivative of
x^3 with respect to x.
The expression being differentiated can itself contain diff.