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

Function legmulx

numpy/polynomial/legendre.py:408–461  ·  view source on GitHub ↗

Multiply a Legendre series by x. Multiply the Legendre series `c` by x, where x is the independent variable. Parameters ---------- c : array_like 1-D array of Legendre series coefficients ordered from low to high. Returns ------- out : ndarray

(c)

Source from the content-addressed store, hash-verified

406
407
408def legmulx(c):
409 """Multiply a Legendre series by x.
410
411 Multiply the Legendre series `c` by x, where x is the independent
412 variable.
413
414
415 Parameters
416 ----------
417 c : array_like
418 1-D array of Legendre series coefficients ordered from low to
419 high.
420
421 Returns
422 -------
423 out : ndarray
424 Array representing the result of the multiplication.
425
426 See Also
427 --------
428 legadd, legmul, legdiv, legpow
429
430 Notes
431 -----
432 The multiplication uses the recursion relationship for Legendre
433 polynomials in the form
434
435 .. math::
436
437 xP_i(x) = ((i + 1)*P_{i + 1}(x) + i*P_{i - 1}(x))/(2i + 1)
438
439 Examples
440 --------
441 >>> from numpy.polynomial import legendre as L
442 >>> L.legmulx([1,2,3])
443 array([ 0.66666667, 2.2, 1.33333333, 1.8]) # may vary
444
445 """
446 # c is a trimmed copy
447 [c] = pu.as_series([c])
448 # The zero series needs special treatment
449 if len(c) == 1 and c[0] == 0:
450 return c
451
452 prd = np.empty(len(c) + 1, dtype=c.dtype)
453 prd[0] = c[0]*0
454 prd[1] = c[0]
455 for i in range(1, len(c)):
456 j = i + 1
457 k = i - 1
458 s = i + j
459 prd[j] = (c[i]*j)/s
460 prd[k] += (c[i]*i)/s
461 return prd
462
463
464def legmul(c1, c2):

Callers 2

poly2legFunction · 0.85
legmulFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected