Skip to content

compute polynomial

kgryte edited this page May 12, 2015 · 1 revision

Evaluates a polynomial whose coefficients are defined by coef. x may be either a single numeric value or an array of values at which to evaluate to the polynomial.

var coef = [ 4, 2, 6, -17 ];

var vals = compute.polyval( coef, [ 10, -3] );
// returns [ 4243, -125 ]

For object arrays, provide an accessor function for accessing array values.

var coefs = [ 4, 2, 6, -17 ];

var data = [
    ['beep', 10],
    ['boop', -3]
];

function getValue( d, i ) {
    return d[ 1 ];
}

var vals = compute.polyval( coefs, data, {
    'accessor': getValue
});
// returns [ 4243, -125 ]

For additional options, see compute-polynomial.

Clone this wiki locally