Skip to content

Instantly share code, notes, and snippets.

@folkertdev
folkertdev / lagrangePolynomial.py
Created September 27, 2015 14:12
A sympy-based Lagrange polynomial constructor
"""
A sympy-based Lagrange polynomial constructor.
Given a set of function inputs and outputs, the lagrangePolynomial function will construct an
expression that for every input gives the corresponding output. For intermediate values,
the polynomial interpolates (giving varying results based on the shape of your input).
This is useful when the result needs to be used outside of Python, because the
expression can easily be copied. To convert the expression to a python function object,
use sympy.lambdify.
"""