ndarray-function-basis
v2.0.0
Published
Construct an basis ndarray given a list of values and functions
Downloads
21
Readme
ndarray-function-basis
Construct an basis ndarray given a list of values and functions
Introduction
This module extends the Vandermonde matrix to a list of numbers or functions. It constructs a set of basis vectors that can be used in a least squares curve fit. It's little more than a thin convenience wrapper around ndarray-fill.
Usage
require([dest, ]x, inputs)
dest
: a destination array. If not provided, anndarray
of type'array'
will be created. If provided, the first dimension must match the length ofx
, and the second must match the length ofinputs
.x
: a ndarray of numbers at which the inputs are evaluatedinputs
: anArray
of eitherFunctions
orNumbers
. If aFunction
, it is evaluated atx
; if aNumber
,x
is ignored for this input.
Example
For example, to construct a sinusoidal basis with period 2 * π
and a constant offset,
var basis = require('ndarray-function-basis');
var ndarray = require('ndarray');
basis(ndarray([1, 2, 3, 4]), [1, Math.sin, Math.cos]);
// =>
// 1.000 0.841 0.540
// 1.000 0.909 -0.416
// 1.000 0.141 -0.990
// 1.000 -0.757 -0.654
See also:
- ndarray-householder-qr: Householder QR for least squares curve-fitting
- ndarray-vandermonde: Construct a Vandermonde (polynomial) basis
Credits
(c) 2015 Ricky Reusser. MIT License