README
approximate.js
example:
const approximate = require('approximate-function');
var segmentsPoints = [];
for (var i = -1; i <= 1; i += 0.4) {
segmentsPoints.push(i);
}
var approxCos = approximate.simple(segmentsPoints, Math.cos);
for (var i = -1; i <= 1; i += 0.1) {
console.log(Math.cos(i) + " <=> " + approxCos(i));
}
will output:
0.5403023058681398 <=> 0.5403023058681398
0.6216099682706644 <=> 0.6115606331285244
0.6967067093471654 <=> 0.682818960388909
0.7648421872844884 <=> 0.7540772876492936
0.8253356149096782 <=> 0.8253356149096782
0.8775825618903726 <=> 0.8640183556425691
0.921060994002885 <=> 0.9027010963754599
0.955336489125606 <=> 0.9413838371083507
0.9800665778412416 <=> 0.9800665778412415
0.9950041652780257 <=> 0.9800665778412416
1 <=> 0.9800665778412416
0.9950041652780258 <=> 0.9800665778412416
0.9800665778412416 <=> 0.9800665778412416
0.9553364891256061 <=> 0.9413838371083508
0.9210609940028851 <=> 0.90270109637546
0.8775825618903728 <=> 0.8640183556425691
0.8253356149096784 <=> 0.8253356149096783
0.7648421872844885 <=> 0.7540772876492938
0.6967067093471655 <=> 0.6828189603889092
0.6216099682706646 <=> 0.6115606331285246
0.5403023058681399 <=> 0.54030230586814