Menu

Home

Dominik R.

pure python polyfit

Welcome to pure python polyfit, the polynomial fitting without any third party module like numpy, scipy, etc.

You can fit polynomials in 1D, 2D or generally in N-D.

Also you can solve a system of least squares or compute A= Q*R for a matrix A.
It is all based on list representations of coordinates and matrices.

The functionality is tested with the unit test script "testPurePythonPolyFit.py". This test actually needs numpy for verification.

Examples:

In this section you can find examples for polyfitting, QR decomposition and least squares solving

Example: Polynomial Fitting

(conceptual, see also end of "purePythonPolyFit.py" for example usage):

# estimate 1D, x and y lists of floats
p = PolyFit(x, y, order=2)
# evaluate 1D
p[0.5]

# estimate 2D, pts list of tuples/list of length 2
#  (e.g. pts = [(1.0, 4.1),(4.2, 0.1), ...])
# vals: list of floats
p2 = PolyFit2D(pts, vals, order=3)
# evaluate 2D
p2[(0.5, 1.0)]

# estimate N-D, pts list of tuples/list of length N
# (e.g. [(1.0, 4.1, 0, 0),(0, 4.2, 0, 0.1), ...])
# vals: list of floats
pn = PolyFitND(pts, vals, order=3)
# evaluate N-D
pn[(0.5, 1.0, 0.2, 0.2)]

Example: QR Decomposition of a Matrix

# matrix are represented with lists of lists/tuples:
A=[[1,2,3],[4,5,6]]
# the result:
Q,R = qr(A)

Example: Solve Least Squares system

Find a least squares solution x, for the system Ax =y

# a random overdetermined matrix:
A=[[1,2],[2,5],[5,4]]
# a noise measurement vector:
b=[1,2,3]
# the result:
solution, residual = leastSquareSolution(A,b)

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.