Convert a Legendre series to a polynomial. Convert an array representing the coefficients of a Legendre series, ordered from lowest degree to highest, to an array of the coefficients of the equivalent polynomial (relative to the "standard" basis) ordered from lowest to highest
(c)
| 146 | |
| 147 | |
| 148 | def leg2poly(c): |
| 149 | """ |
| 150 | Convert a Legendre series to a polynomial. |
| 151 | |
| 152 | Convert an array representing the coefficients of a Legendre series, |
| 153 | ordered from lowest degree to highest, to an array of the coefficients |
| 154 | of the equivalent polynomial (relative to the "standard" basis) ordered |
| 155 | from lowest to highest degree. |
| 156 | |
| 157 | Parameters |
| 158 | ---------- |
| 159 | c : array_like |
| 160 | 1-D array containing the Legendre series coefficients, ordered |
| 161 | from lowest order term to highest. |
| 162 | |
| 163 | Returns |
| 164 | ------- |
| 165 | pol : ndarray |
| 166 | 1-D array containing the coefficients of the equivalent polynomial |
| 167 | (relative to the "standard" basis) ordered from lowest order term |
| 168 | to highest. |
| 169 | |
| 170 | See Also |
| 171 | -------- |
| 172 | poly2leg |
| 173 | |
| 174 | Notes |
| 175 | ----- |
| 176 | The easy way to do conversions between polynomial basis sets |
| 177 | is to use the convert method of a class instance. |
| 178 | |
| 179 | Examples |
| 180 | -------- |
| 181 | >>> from numpy import polynomial as P |
| 182 | >>> c = P.Legendre(range(4)) |
| 183 | >>> c |
| 184 | Legendre([0., 1., 2., 3.], domain=[-1, 1], window=[-1, 1]) |
| 185 | >>> p = c.convert(kind=P.Polynomial) |
| 186 | >>> p |
| 187 | Polynomial([-1. , -3.5, 3. , 7.5], domain=[-1., 1.], window=[-1., 1.]) |
| 188 | >>> P.legendre.leg2poly(range(4)) |
| 189 | array([-1. , -3.5, 3. , 7.5]) |
| 190 | |
| 191 | |
| 192 | """ |
| 193 | from .polynomial import polyadd, polysub, polymulx |
| 194 | |
| 195 | [c] = pu.as_series([c]) |
| 196 | n = len(c) |
| 197 | if n < 3: |
| 198 | return c |
| 199 | else: |
| 200 | c0 = c[-2] |
| 201 | c1 = c[-1] |
| 202 | # i is the current degree of c1 |
| 203 | for i in range(n - 1, 1, -1): |
| 204 | tmp = c0 |
| 205 | c0 = polysub(c[i - 2], (c1*(i - 1))/i) |