Numbers.js adds a bit of advanced mathematics to the standard mathematical capabilities of JavaScript — integrals, operations on matrices and complex numbers, statistical functions, factorization, and some other functions. In addition, the library determines the basic arithmetic operations on arrays - addition, subtraction and multiplication of elements, the search for minimum and maximum, random mixing of the array and allows you to explicitly specify the required accuracy of calculations, which helps to avoid rounding errors.
Examples of using
We connect the library under Node.js and calculate the Riemann integral (divided into 200 segments and an accuracy of 0.0001):
var numbers = require('numbers'); numbers.calculus.riemann(Math.sin, -2, 4, 200, 0.0001);
Using your own functions:
var myFunc = function(x) { return 2*Math.pow(x,2) + 1; } numbers.calculus.riemann(myFunc, -2, 4, 200);
Statistical functions:
')
numbers.statistic.mean(array); numbers.statistic.median(array); numbers.statistic.mode(array); numbers.statistic.standardDev(array); numbers.statistic.randomSample(lower, upper, n); numbers.statistic.correlation(array1, array2);
Addition of matrices:
var array1 = [0, 1, 2]; var array2 = [3, 4, 5]; numbers.matrix.addition(array1, array2);
The greatest common factor is:
numbers.basic.gcd(x, y);
The library is only about a month old, but it was able to attract the attention of developers on Github and is actively replenishing (a couple of weeks ago, the set of functions was almost twice as modest).
Links
Gitkhab ,
documentation .