MCPcopy Create free account
hub / github.com/numpy/numpy / poly2leg

Function poly2leg

numpy/polynomial/legendre.py:100–145  ·  view source on GitHub ↗

Convert a polynomial to a Legendre series. Convert an array representing the coefficients of a polynomial (relative to the "standard" basis) ordered from lowest degree to highest, to an array of the coefficients of the equivalent Legendre series, ordered from lowest to highest

(pol)

Source from the content-addressed store, hash-verified

98
99
100def poly2leg(pol):
101 """
102 Convert a polynomial to a Legendre series.
103
104 Convert an array representing the coefficients of a polynomial (relative
105 to the "standard" basis) ordered from lowest degree to highest, to an
106 array of the coefficients of the equivalent Legendre series, ordered
107 from lowest to highest degree.
108
109 Parameters
110 ----------
111 pol : array_like
112 1-D array containing the polynomial coefficients
113
114 Returns
115 -------
116 c : ndarray
117 1-D array containing the coefficients of the equivalent Legendre
118 series.
119
120 See Also
121 --------
122 leg2poly
123
124 Notes
125 -----
126 The easy way to do conversions between polynomial basis sets
127 is to use the convert method of a class instance.
128
129 Examples
130 --------
131 >>> from numpy import polynomial as P
132 >>> p = P.Polynomial(np.arange(4))
133 >>> p
134 Polynomial([0., 1., 2., 3.], domain=[-1, 1], window=[-1, 1])
135 >>> c = P.Legendre(P.legendre.poly2leg(p.coef))
136 >>> c
137 Legendre([ 1. , 3.25, 1. , 0.75], domain=[-1, 1], window=[-1, 1]) # may vary
138
139 """
140 [pol] = pu.as_series([pol])
141 deg = len(pol) - 1
142 res = 0
143 for i in range(deg, -1, -1):
144 res = legadd(legmulx(res), pol[i])
145 return res
146
147
148def leg2poly(c):

Callers

nothing calls this directly

Calls 2

legaddFunction · 0.85
legmulxFunction · 0.85

Tested by

no test coverage detected