sm-integral
Compute definite and improper integrals with Romberg Integration. Easily and accurately integrate JavaScript functions.
Features
- Easily evaluate definite and improper integrals.
- Control the order of accuracy (see "Order of Accuracy").
- Fast computation time (see "Tests").
- Divide-by-zero safeguard.
Install
npm install sm-integral
Usage
Below, we demonstrate how to evaluate the following integrals:
and
respectively.
const Integral = ; //definite function to integrate { return 1 / x * x;} //definite integralconsole; //0.1 //improper integralconsole; //0.1
Configuration
The integrate() function has the following parameters.
//... { //... }
f
is the JavaScript function to be integrated.a
is the lower bound of the integral (must either be a number or "inf"/"-inf").b
is the upper bound of the integral (must either be a number or "inf"/"-inf").e
is the order of accuracy (must be a positive even integer - if it is odd, it will be incremented). The default value of 18 is enough to evaluate most integrals to at least +-1e-9 accuracy (see "Tests").
Order of Accuracy
To have an order of accuracy e
means that the returnedValue
when computing
satisfies
Note that for improper integrals, the substitution y=1/x is made.
Tests
In the test folder, 8 integrals are tested with the default e=18
parameter. The 8 evaluations were completed within 30ms, each producing results accurate to at least +-1e-9.
;