4.8 Numerical integration and differentiationTwo special functions, int_dx() and diff_dx(), may be used to integrate or differentiate algebraic expressions numerically. In each case, the letter x is the dummy variable which is to be used in the integration or differentiation and may be replaced by any valid variable name of up to 16 characters in length. The function int_dx() takes three parameters – firstly the expression to be integrated, which may optionally be placed in quotes, followed by the minimum and maximum integration limits. These may have any physical dimensions, so long as they match, but must both be real numbers. 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 one further optional parameter. The first is the expression to be differentiated, which, as above, may optionally placed in quotes for clarity. This should be followed by the numerical value
When complex arithmetic is enabled, Pyxplot checks that the function being differentiated satisfies the Cauchy-Riemann equations, and returns an error if it does not, to indicate that it is not differentiable. The following is an example of a function which is not differentiable, and which throws an error because the Cauchy-Riemann equations are not satisfied:
Advanced users may be interested to know that int_dx() function is implemented using the gsl_integration_qags() function of the Gnu Scientific Library (GSL), and the diff_dx() function is implemented using the gsl_deriv_central() function of the same library. Any caveats which apply to the use of these routines also apply to Pyxplot’s numerical calculus. Example: Integrating the function ![]() The function ![]()
![]() set samples 80 set key bottom right set xformat r"%s$ ![]() set yformat r"%s$ ![]() set xrange [-5*pi:5*pi] plot int_dz(sinc(z),0,x) ![]()
|