Skip to content

turn an array of points into the coefficients for the polynomial which crosses those points

Notifications You must be signed in to change notification settings

elliot-mb/points-to-polynomial

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Polynomial from points

When I first discovered this process I couldn't believe how elegant it was, which motivated me to implement it.
This Haskell script turns n distinct points into its unique corresponding polynomial of degree n-1 (casual proof).
This is accomplished by entering the points into a Gaussian Elimination matrix that looks like this:

For any array of m + 1 distinct points with no common x coordinates
[ 1    x0   x0^2 x0^3 ...  x0^m    y0  ]
[ 1    x1   x1^2 x1^3 ...  x1^m    y1  ]
[ ...  ...  ...  ...  ...  ...     ... ]
[ 1    xm   xm^2 xm^3 ...  xm^m    ym  ]

...which is then solved for the coefficients of x^0 (1), x^1, x^2, ...
To get a polynomial from these coefficients (c0, c1, c2, ...), write:

c0 * 1 + c1 * x + c2 * x^2 + c3 * x^3 + ... + cm * x^m = y

This algorithm contains my Haskell implementation of generic Gaussian Elimination, which is used to solve for the aforementioned coefficients.

Example

Script

picture

Shown in Desmos

picture

About

turn an array of points into the coefficients for the polynomial which crosses those points

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published