Tools for Mathematical Analysis
npm install math-analysisMATH-ANALYSIS can be used to perform various operations pertaining
to mathematical analysis such as (symbolic) differentiation,
(numeric and symbolic) integration etc.

bash
$ npm install math-analysis
`Usage
`js
var ma = require('math-analysis');
``ma` exposes the following functions:$3
Creates a function (object) from the given string specification.
The specification follows standard syntax, using the following
built-in functions:*
`sqrt(x)`: square root of _x_*
`log(x)`: natural logarithm (basis _e_)*
`exp(x)`: _e_ to the power of _x_*
`pow(x,y)`: _x_ to the power of _y_*
`sin(x)`: trigonometric function _sine_*
`cos(x)`: trigonometric function _cosine_*
`PI`: constant _π_Note: all built-in functions are computed through the respective function offered by
`Math`, i.e.
`Math.sqrt`, `Math.log` etc.#### _Example_:
`js
var f = ma.createFunction('2.1 * sqrt(x + 1/x)');
`The function object created, henceforth denoted by _f_, has the following methods:
#### eval(x)
Returns the function value _f(x)_ for the given
`x`.#### differentiate()
Returns a function (object) that represents the (symbolically) differentiated
_f_ or the derivative of _f_.
#### integral(a,b,s)
Computes the integral of _f_ over the interval [a;b].
`a` and `b` must be provided and must be numbers. Otherwise the return value is undefined.
The integral is computed as _F(b) - F(a)_ for the antiderivative _F_ of _f_ if such
an _F_ can be determined (see __integrate__). Otherwise a numeric approximation of the integral is computed.In the case of a numeric approach
parameter
`s` defines the number of sub-intervals into which [a;b] is "chopped"
to approximate the integral. This parameter is an optional integer number
not less than 1. If it is not supplied or invalid the default 1000 is used. The bigger the value
of `s` the more accurate the approximation. It will nonetheless remain an approximation. So there is
no guarantee that the approximation and the exact value will be the same.Note that the value of the approximation will be undefined if
`NaN` was encountered
when computing the approximation. Keep in mind, however, that the existence of an _x_ in [a;b]
for which the function is undefined does not necessarily mean that `NaN` is indeed encountered.
Depending on _a_ and parameter `s` such an _x_ may be "skipped".#### integrate()
Returns the antiderivative of _f_ (as a function). Computation of an antiderivative
may not always succeed. If it fails the return value is undefined, which does not necessarily mean
that there is no (known) antiderivative. The procedure for computing the
antiderivative implemented here has limitations that will be lifted to a certain extent with
future versions, but will (or can) never be fully removed. (See also __integral__).
#### rewrite()
Returns a function that is a simplified version of _f_. For instance,
`x + 0` becomes `x` and `(1+2)x - x` becomes `2 x` etc.
Note that rewriting may modify _f_. That is, rewriting does not
return a rewritten copy of _f_, but rather operates on _f_ itself.
Thus, the return value can be ignored as it is merely a pointer to _f_ itself
that may come in handy for method-chaining.
Hence it is always true that `f === f.rewrite()`.If for some reason you want to retain _f_ as it was before rewriting simply store
its string representation and, if required, apply
`ma.createFunction` to the string
to obtain a function object again.##### _Example_
`js
var f = ma.createFunction('x + 0');
var s1 = f.toString();
f.rewrite();
var s2 = f.toString();
`
Having executed the above code the two string variables `s1` and `s2` hold the
strings `'x + 0'` and `'x'`, respectively.#### toString()
Returns the string representation of the function.
$3
Creates a look-up table for the given function `fct` with values for `x`
ranging from `from` to `to` using the given step size `step`.
`fct` must have been created with `createFunction`. The other
three parameters are also mandatory and must be of type `number`.
Furthermore, `step` must be greater than `0` and `from` must not
be greater than `to`. If any of these prerequisites are not met
the return value of this function is undefined.#### _Example_:
`js
var f = ma.createFunction('2*x+1');
var t = ma.lookupTable(f,-1,2.1,0.5);
`
As a result `t` is
`[{x:-1,y:-1},{x:-0.5,y:0},{x:0,y:1},{x:0.5,y:2},{x:1,y:3},{x:1.5,y:4},{x:2,y:5}]``.