MCPcopy Index your code
hub / github.com/numpy/numpy / chebvander

Function chebvander

numpy/polynomial/chebyshev.py:1406–1456  ·  view source on GitHub ↗

Pseudo-Vandermonde matrix of given degree. Returns the pseudo-Vandermonde matrix of degree `deg` and sample points `x`. The pseudo-Vandermonde matrix is defined by .. math:: V[..., i] = T_i(x), where ``0 <= i <= deg``. The leading indices of `V` index the elements of `x` and t

(x, deg)

Source from the content-addressed store, hash-verified

1404
1405
1406def chebvander(x, deg):
1407 """Pseudo-Vandermonde matrix of given degree.
1408
1409 Returns the pseudo-Vandermonde matrix of degree `deg` and sample points
1410 `x`. The pseudo-Vandermonde matrix is defined by
1411
1412 .. math:: V[..., i] = T_i(x),
1413
1414 where ``0 <= i <= deg``. The leading indices of `V` index the elements of
1415 `x` and the last index is the degree of the Chebyshev polynomial.
1416
1417 If `c` is a 1-D array of coefficients of length ``n + 1`` and `V` is the
1418 matrix ``V = chebvander(x, n)``, then ``np.dot(V, c)`` and
1419 ``chebval(x, c)`` are the same up to roundoff. This equivalence is
1420 useful both for least squares fitting and for the evaluation of a large
1421 number of Chebyshev series of the same degree and sample points.
1422
1423 Parameters
1424 ----------
1425 x : array_like
1426 Array of points. The dtype is converted to float64 or complex128
1427 depending on whether any of the elements are complex. If `x` is
1428 scalar it is converted to a 1-D array.
1429 deg : int
1430 Degree of the resulting matrix.
1431
1432 Returns
1433 -------
1434 vander : ndarray
1435 The pseudo Vandermonde matrix. The shape of the returned matrix is
1436 ``x.shape + (deg + 1,)``, where The last index is the degree of the
1437 corresponding Chebyshev polynomial. The dtype will be the same as
1438 the converted `x`.
1439
1440 """
1441 ideg = pu._as_int(deg, "deg")
1442 if ideg < 0:
1443 raise ValueError("deg must be non-negative")
1444
1445 x = np.array(x, copy=None, ndmin=1) + 0.0
1446 dims = (ideg + 1,) + x.shape
1447 dtyp = x.dtype
1448 v = np.empty(dims, dtype=dtyp)
1449 # Use forward recursion to generate the entries.
1450 v[0] = x * 0 + 1
1451 if ideg > 0:
1452 x2 = 2 * x
1453 v[1] = x
1454 for i in range(2, ideg + 1):
1455 v[i] = v[i - 1] * x2 - v[i - 2]
1456 return np.moveaxis(v, 0, -1)
1457
1458
1459def chebvander2d(x, y, deg):

Callers 1

chebinterpolateFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…