Multiply one Legendre series by another. Returns the product of two Legendre series `c1` * `c2`. The arguments are sequences of coefficients, from lowest order "term" to highest, e.g., [1,2,3] represents the series ``P_0 + 2*P_1 + 3*P_2``. Parameters ---------- c1, c2
(c1, c2)
| 462 | |
| 463 | |
| 464 | def legmul(c1, c2): |
| 465 | """ |
| 466 | Multiply one Legendre series by another. |
| 467 | |
| 468 | Returns the product of two Legendre series `c1` * `c2`. The arguments |
| 469 | are sequences of coefficients, from lowest order "term" to highest, |
| 470 | e.g., [1,2,3] represents the series ``P_0 + 2*P_1 + 3*P_2``. |
| 471 | |
| 472 | Parameters |
| 473 | ---------- |
| 474 | c1, c2 : array_like |
| 475 | 1-D arrays of Legendre series coefficients ordered from low to |
| 476 | high. |
| 477 | |
| 478 | Returns |
| 479 | ------- |
| 480 | out : ndarray |
| 481 | Of Legendre series coefficients representing their product. |
| 482 | |
| 483 | See Also |
| 484 | -------- |
| 485 | legadd, legsub, legmulx, legdiv, legpow |
| 486 | |
| 487 | Notes |
| 488 | ----- |
| 489 | In general, the (polynomial) product of two C-series results in terms |
| 490 | that are not in the Legendre polynomial basis set. Thus, to express |
| 491 | the product as a Legendre series, it is necessary to "reproject" the |
| 492 | product onto said basis set, which may produce "unintuitive" (but |
| 493 | correct) results; see Examples section below. |
| 494 | |
| 495 | Examples |
| 496 | -------- |
| 497 | >>> from numpy.polynomial import legendre as L |
| 498 | >>> c1 = (1,2,3) |
| 499 | >>> c2 = (3,2) |
| 500 | >>> L.legmul(c1,c2) # multiplication requires "reprojection" |
| 501 | array([ 4.33333333, 10.4 , 11.66666667, 3.6 ]) # may vary |
| 502 | |
| 503 | """ |
| 504 | # s1, s2 are trimmed copies |
| 505 | [c1, c2] = pu.as_series([c1, c2]) |
| 506 | |
| 507 | if len(c1) > len(c2): |
| 508 | c = c2 |
| 509 | xs = c1 |
| 510 | else: |
| 511 | c = c1 |
| 512 | xs = c2 |
| 513 | |
| 514 | if len(c) == 1: |
| 515 | c0 = c[0]*xs |
| 516 | c1 = 0 |
| 517 | elif len(c) == 2: |
| 518 | c0 = c[0]*xs |
| 519 | c1 = c[1]*xs |
| 520 | else: |
| 521 | nd = len(c) |