Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript equivalent functions to Matlab Functions: Polyfit/Polyval?

Desperately need a Javascript equivalent to polyval and polyfit functions that exist in Matlab. Essentially those functions in matlab do a curve fit based on two equally sized arrays depending on a specified polynomial. I need to do some calculations that involve curve fitting in javascript and can't for the life of me find an equivalent function.

This is MatLab's explanation of the function polyfit

"P = POLYFIT(X,Y,N) finds the coefficients of a polynomial P(X) of degree N that fits the data Y best in a least-squares sense. P is a row vector of length N+1 containing the polynomial coefficients in descending powers, P(1)*X^N + P(2)*X^(N-1) +...+ P(N)*X + P(N+1)."

This is MatLab's explanation of polyval.

"POLYVAL Evaluate polynomial. Y = POLYVAL(P,X) returns the value of a polynomial P evaluated at X. P is a vector of length N+1 whose elements are the coefficients of the polynomial in descending powers.

    Y = P(1)*X^N + P(2)*X^(N-1) + ... + P(N)*X + P(N+1)"

Any help would be super.

Regards,

like image 791
Spets Avatar asked Jul 26 '11 07:07

Spets


1 Answers

numericjs may help you get started.

like image 110
biogeek Avatar answered Oct 13 '22 00:10

biogeek