math-interpolate
Install
$ yarn add math-interpolate
Interpolation cases usage
So, you can use methods below
- linear by
({ x, x1, y1, x2, y2 })
- bilinear by
({ x, y, x1, y1, x2, y2, q11, q12, q21, q22 })
- byInternalTable by
({ x, y, tableAsDoubleArray }
TODO: external cases - getKB for condition like
y = (k * x) + b
by{ x1, y1, x2, y2 }
- getCommonPointByBisectionMethod by
({ fn1, fn2, xMin = -1000, xMax = 1000, eps = 0.001 })
linear
console// 1.5
This example description
|
y2= 2 | o
|
y= ? | o
(1.5 will be found)
y1= 1 o
|
------------------------------------
x1= 0 x= 0.5 x2= 1
bilinear
console// 377.75
This example description
| q12= 410 q22= 590
y2= 5 | o o
|
| q= ? (377.75 will be found)
y= 3.5 | o
|
| q11= 400 q21= 210
y1= 1 | o o
------------------------------------
x1= 1 x= 3 x2= 6
And also, you can read more about bilinear interpolation on wiki.
byInternalTable
Interpolate by table (only internal table values gives correct result) for example
const temperature = -210const percentage = 200/* About table below: 1st horizontal line (highest row as x axis) - temperature conditions template 1st vertical column (first left column as y axis) - percentage conditions template*/const tableAsDoubleArray = 00 -30 -200 -100 00 200 400 600 800 1000 00 419 419 419 419 419 419 419 419 419 250 393 393 393 395 398 40 403 405 408 370 368 368 37 372 377 382 388 394 40 450 349 349 352 356 362 369 376 382 389 console// 3.982
getKB
console// { k: -0.8,// b: 1.8 }
getCommonPointByBisectionMethod
console// { error: false,// x: ~0,// y: ~0 }
This example description
|
y2= 2 o o
|
y= ? | o
(~1.5 will be found)
y1= 1 o o
|
------------------------------------
x1= 0 x= ? x2= 1
(~0.5 will be found)
const k: k1 b: b1 = const k: k2 b: b2 = const fn1 = k1 * x + b1const fn2 = k2 * x + b2 console// { error: false, // & description field if true// x: 0.5002021789550781,// y: 1.5002021789550781 }
Commands
npm run clean
- Removelib/
directorynpm test
- Run tests with linting and coverage results.npm test:only
- Run tests without linting or coverage.npm test:watch
- You can even re-run tests on file changes!npm test:prod
- Run tests with minified code.npm run test:examples
- Test written examples on pure JS for better understanding module usage.npm run lint
- Run ESlint with airbnb-confignpm run cover
- Get coverage report for your code.npm run build
- Babel will transpile ES6 => ES5 and minify the code.npm run prepublish
- Hook for npm. Do all the checks before publishing your module.
License
MIT © Den Pol