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

Function legval

numpy/polynomial/legendre.py:832–914  ·  view source on GitHub ↗

Evaluate a Legendre series at points x. If `c` is of length `n + 1`, this function returns the value: .. math:: p(x) = c_0 * L_0(x) + c_1 * L_1(x) + ... + c_n * L_n(x) The parameter `x` is converted to an array only if it is a tuple or a list, otherwise it is treated as a sca

(x, c, tensor=True)

Source from the content-addressed store, hash-verified

830
831
832def legval(x, c, tensor=True):
833 """
834 Evaluate a Legendre series at points x.
835
836 If `c` is of length `n + 1`, this function returns the value:
837
838 .. math:: p(x) = c_0 * L_0(x) + c_1 * L_1(x) + ... + c_n * L_n(x)
839
840 The parameter `x` is converted to an array only if it is a tuple or a
841 list, otherwise it is treated as a scalar. In either case, either `x`
842 or its elements must support multiplication and addition both with
843 themselves and with the elements of `c`.
844
845 If `c` is a 1-D array, then `p(x)` will have the same shape as `x`. If
846 `c` is multidimensional, then the shape of the result depends on the
847 value of `tensor`. If `tensor` is true the shape will be c.shape[1:] +
848 x.shape. If `tensor` is false the shape will be c.shape[1:]. Note that
849 scalars have shape (,).
850
851 Trailing zeros in the coefficients will be used in the evaluation, so
852 they should be avoided if efficiency is a concern.
853
854 Parameters
855 ----------
856 x : array_like, compatible object
857 If `x` is a list or tuple, it is converted to an ndarray, otherwise
858 it is left unchanged and treated as a scalar. In either case, `x`
859 or its elements must support addition and multiplication with
860 themselves and with the elements of `c`.
861 c : array_like
862 Array of coefficients ordered so that the coefficients for terms of
863 degree n are contained in c[n]. If `c` is multidimensional the
864 remaining indices enumerate multiple polynomials. In the two
865 dimensional case the coefficients may be thought of as stored in
866 the columns of `c`.
867 tensor : boolean, optional
868 If True, the shape of the coefficient array is extended with ones
869 on the right, one for each dimension of `x`. Scalars have dimension 0
870 for this action. The result is that every column of coefficients in
871 `c` is evaluated for every element of `x`. If False, `x` is broadcast
872 over the columns of `c` for the evaluation. This keyword is useful
873 when `c` is multidimensional. The default value is True.
874
875 .. versionadded:: 1.7.0
876
877 Returns
878 -------
879 values : ndarray, algebra_like
880 The shape of the return value is described above.
881
882 See Also
883 --------
884 legval2d, leggrid2d, legval3d, leggrid3d
885
886 Notes
887 -----
888 The evaluation uses Clenshaw recursion, aka synthetic division.
889

Callers 2

legintFunction · 0.85
leggaussFunction · 0.85

Calls 2

astypeMethod · 0.80
reshapeMethod · 0.80

Tested by

no test coverage detected