chaospy.expansion.lagrange

chaospy.expansion.lagrange(abscissas, graded=True, reverse=True, sort=None)[source]

Create Lagrange polynomial expansion.

Args:
abscissas (numpy.ndarray):

Sample points where the Lagrange polynomials shall be defined.

graded (bool):

Graded sorting, meaning the indices are always sorted by the index sum. E.g. q0**2*q1**2*q2**2 has an exponent sum of 6, and will therefore be consider larger than both q0**2*q1*q2, q0*q1**2*q2 and q0*q1*q2**2, which all have exponent sum of 5.

reverse (bool):

Reverse lexicographical sorting meaning that q0*q1**3 is considered bigger than q0**3*q1, instead of the opposite.

Example:
>>> chaospy.expansion.lagrange([4]).round(4)
polynomial([4.0])
>>> chaospy.expansion.lagrange([-10, 10]).round(4)
polynomial([-0.05*q0+0.5, 0.05*q0+0.5])
>>> chaospy.expansion.lagrange([-1, 0, 1]).round(4)
polynomial([0.5*q0**2-0.5*q0, -q0**2+1.0, 0.5*q0**2+0.5*q0])
>>> poly = chaospy.expansion.lagrange([[1, 0, 1], [0, 1, 2]])
>>> poly.round(4)
polynomial([-0.5*q1+0.5*q0+0.5, -q0+1.0, 0.5*q1+0.5*q0-0.5])
>>> poly([1, 0, 1], [0, 1, 2]).round(14)
array([[1., 0., 0.],
       [0., 1., 0.],
       [0., 0., 1.]])
>>> nodes = numpy.array([[ 0.17,  0.15,  0.17,  0.19],
...                      [14.94, 16.69, 16.69, 16.69]])
>>> poly = chaospy.expansion.lagrange(nodes)  
Traceback (most recent call last):
    ...
LinAlgError: Lagrange abscissas resulted in invertible matrix