Special functions are available for performing numerical integration and differentiation of expressions: int_dx() and diff_dx(). In each case, the ‘x’ may be replaced with any valid one-letter variable name, to integrate or differentiate with respect to that dummy variable.
The function int_dx() takes three parameters – firstly the expression to be integrated, which should be placed in quotes as a string, followed by the minimum and maximum integration limits. For example, the following would plot the integral of the function :
plot int_dt('sin(t)',0,x)
The function diff_dx() takes two obligatory parameters plus two further optional parameters. The first is the expression to be differentiated, which, as above, should be placed in quotes as a string, followed by the point at which the differential should be evaluated, followed by optional parameters and
which are described below. The following example would evaluate the differential of the function
with respect to
at
:
print diff_dx('cos(x)', 1.0)
Differentials are evaluated by a simple differencing algorithm, and a parameter controls the spacing with which to perform the differencing operation:
![]() |
where . By default,
, which is appropriate for the differentiation of most well-behaved functions.
Advanced users may be interested to know that integration is performed using the quad function of the integrate package of the scipy numerical toolkit for Python – a general purpose integration routine.