Convert a polynomial to a Chebyshev 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 Chebyshev series, ordered from lowest to highes
(pol)
| 345 | |
| 346 | |
| 347 | def poly2cheb(pol): |
| 348 | """ |
| 349 | Convert a polynomial to a Chebyshev series. |
| 350 | |
| 351 | Convert an array representing the coefficients of a polynomial (relative |
| 352 | to the "standard" basis) ordered from lowest degree to highest, to an |
| 353 | array of the coefficients of the equivalent Chebyshev series, ordered |
| 354 | from lowest to highest degree. |
| 355 | |
| 356 | Parameters |
| 357 | ---------- |
| 358 | pol : array_like |
| 359 | 1-D array containing the polynomial coefficients |
| 360 | |
| 361 | Returns |
| 362 | ------- |
| 363 | c : ndarray |
| 364 | 1-D array containing the coefficients of the equivalent Chebyshev |
| 365 | series. |
| 366 | |
| 367 | See Also |
| 368 | -------- |
| 369 | cheb2poly |
| 370 | |
| 371 | Notes |
| 372 | ----- |
| 373 | The easy way to do conversions between polynomial basis sets |
| 374 | is to use the convert method of a class instance. |
| 375 | |
| 376 | Examples |
| 377 | -------- |
| 378 | >>> from numpy import polynomial as P |
| 379 | >>> p = P.Polynomial(range(4)) |
| 380 | >>> p |
| 381 | Polynomial([0., 1., 2., 3.], domain=[-1, 1], window=[-1, 1]) |
| 382 | >>> c = p.convert(kind=P.Chebyshev) |
| 383 | >>> c |
| 384 | Chebyshev([1. , 3.25, 1. , 0.75], domain=[-1., 1.], window=[-1., 1.]) |
| 385 | >>> P.chebyshev.poly2cheb(range(4)) |
| 386 | array([1. , 3.25, 1. , 0.75]) |
| 387 | |
| 388 | """ |
| 389 | [pol] = pu.as_series([pol]) |
| 390 | deg = len(pol) - 1 |
| 391 | res = 0 |
| 392 | for i in range(deg, -1, -1): |
| 393 | res = chebadd(chebmulx(res), pol[i]) |
| 394 | return res |
| 395 | |
| 396 | |
| 397 | def cheb2poly(c): |