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 the
(x, deg)
| 1385 | |
| 1386 | |
| 1387 | def chebvander(x, deg): |
| 1388 | """Pseudo-Vandermonde matrix of given degree. |
| 1389 | |
| 1390 | Returns the pseudo-Vandermonde matrix of degree `deg` and sample points |
| 1391 | `x`. The pseudo-Vandermonde matrix is defined by |
| 1392 | |
| 1393 | .. math:: V[..., i] = T_i(x), |
| 1394 | |
| 1395 | where `0 <= i <= deg`. The leading indices of `V` index the elements of |
| 1396 | `x` and the last index is the degree of the Chebyshev polynomial. |
| 1397 | |
| 1398 | If `c` is a 1-D array of coefficients of length `n + 1` and `V` is the |
| 1399 | matrix ``V = chebvander(x, n)``, then ``np.dot(V, c)`` and |
| 1400 | ``chebval(x, c)`` are the same up to roundoff. This equivalence is |
| 1401 | useful both for least squares fitting and for the evaluation of a large |
| 1402 | number of Chebyshev series of the same degree and sample points. |
| 1403 | |
| 1404 | Parameters |
| 1405 | ---------- |
| 1406 | x : array_like |
| 1407 | Array of points. The dtype is converted to float64 or complex128 |
| 1408 | depending on whether any of the elements are complex. If `x` is |
| 1409 | scalar it is converted to a 1-D array. |
| 1410 | deg : int |
| 1411 | Degree of the resulting matrix. |
| 1412 | |
| 1413 | Returns |
| 1414 | ------- |
| 1415 | vander : ndarray |
| 1416 | The pseudo Vandermonde matrix. The shape of the returned matrix is |
| 1417 | ``x.shape + (deg + 1,)``, where The last index is the degree of the |
| 1418 | corresponding Chebyshev polynomial. The dtype will be the same as |
| 1419 | the converted `x`. |
| 1420 | |
| 1421 | """ |
| 1422 | ideg = pu._deprecate_as_int(deg, "deg") |
| 1423 | if ideg < 0: |
| 1424 | raise ValueError("deg must be non-negative") |
| 1425 | |
| 1426 | x = np.array(x, copy=False, ndmin=1) + 0.0 |
| 1427 | dims = (ideg + 1,) + x.shape |
| 1428 | dtyp = x.dtype |
| 1429 | v = np.empty(dims, dtype=dtyp) |
| 1430 | # Use forward recursion to generate the entries. |
| 1431 | v[0] = x*0 + 1 |
| 1432 | if ideg > 0: |
| 1433 | x2 = 2*x |
| 1434 | v[1] = x |
| 1435 | for i in range(2, ideg + 1): |
| 1436 | v[i] = v[i-1]*x2 - v[i-2] |
| 1437 | return np.moveaxis(v, 0, -1) |
| 1438 | |
| 1439 | |
| 1440 | def chebvander2d(x, y, deg): |