[Numpy-svn] r8643 - in branches/1.5.x: doc/release numpy/polynomial numpy/polynomial/tests

numpy-svn at scipy.org numpy-svn at scipy.org
Sun Aug 15 17:12:27 EDT 2010


Author: charris
Date: 2010-08-15 16:12:27 -0500 (Sun, 15 Aug 2010)
New Revision: 8643

Modified:
   branches/1.5.x/doc/release/1.5.0-notes.rst
   branches/1.5.x/numpy/polynomial/chebyshev.py
   branches/1.5.x/numpy/polynomial/tests/test_chebyshev.py
Log:
ENH: Backport r8641-r8642 from trunk.


Modified: branches/1.5.x/doc/release/1.5.0-notes.rst
===================================================================
--- branches/1.5.x/doc/release/1.5.0-notes.rst	2010-08-15 21:06:29 UTC (rev 8642)
+++ branches/1.5.x/doc/release/1.5.0-notes.rst	2010-08-15 21:12:27 UTC (rev 8643)
@@ -111,6 +111,7 @@
 * Weights can be used in both chebfit and Chebyshev.fit
 * A linspace method has been added to the Chebyshev class to ease plotting.
 * The chebmulx function was added.
+* Added functions for the Chebyshev points of the first and second kind.
 
 
 histogram

Modified: branches/1.5.x/numpy/polynomial/chebyshev.py
===================================================================
--- branches/1.5.x/numpy/polynomial/chebyshev.py	2010-08-15 21:06:29 UTC (rev 8642)
+++ branches/1.5.x/numpy/polynomial/chebyshev.py	2010-08-15 21:12:27 UTC (rev 8643)
@@ -36,6 +36,8 @@
 - `chebroots` -- find the roots of a Chebyshev series.
 - `chebvander` -- Vandermonde-like matrix for Chebyshev polynomials.
 - `chebfit` -- least-squares fit returning a Chebyshev series.
+- `chebpts1` -- Chebyshev points of the first kind.
+- `chebpts2` -- Chebyshev points of the second kind.
 - `chebtrim` -- trim leading coefficients from a Chebyshev series.
 - `chebline` -- Chebyshev series of given straight line.
 - `cheb2poly` -- convert a Chebyshev series to a polynomial.
@@ -78,7 +80,8 @@
 __all__ = ['chebzero', 'chebone', 'chebx', 'chebdomain', 'chebline',
         'chebadd', 'chebsub', 'chebmulx', 'chebmul', 'chebdiv', 'chebval',
         'chebder', 'chebint', 'cheb2poly', 'poly2cheb', 'chebfromroots',
-        'chebvander', 'chebfit', 'chebtrim', 'chebroots', 'Chebyshev']
+        'chebvander', 'chebfit', 'chebtrim', 'chebroots', 'chebpts1',
+        'chebpts2', 'Chebyshev']
 
 import numpy as np
 import numpy.linalg as la
@@ -1332,6 +1335,68 @@
     return roots
 
 
+def chebpts1(npts):
+    """Chebyshev points of the first kind.
+
+    Chebyshev points of the first kind are the set ``{cos(x_k)}``,
+    where ``x_k = pi*(k + .5)/npts`` for k in ``range(npts}``.
+
+    Parameters
+    ----------
+    npts: int
+        Number of sample points desired.
+
+    Returns
+    -------
+    pts: ndarray
+        The Chebyshev points of the second kind.
+
+    Notes
+    -----
+    .. versionadded:: 1.5.0
+
+    """
+    _npts = int(npts)
+    if _npts != npts:
+        raise ValueError("npts must be integer")
+    if _npts < 1:
+        raise ValueError("npts must be >= 1")
+
+    x = np.linspace(-np.pi, 0, _npts, endpoint=False) + np.pi/(2*_npts)
+    return np.cos(x)
+
+
+def chebpts2(npts):
+    """Chebyshev points of the second kind.
+
+    Chebyshev points of the second kind are the set ``{cos(x_k)}``,
+    where ``x_k = pi*/(npts - 1)`` for k in ``range(npts}``.
+
+    Parameters
+    ----------
+    npts: int
+        Number of sample points desired.
+
+    Returns
+    -------
+    pts: ndarray
+        The Chebyshev points of the second kind.
+
+    Notes
+    -----
+    .. versionadded:: 1.5.0
+
+    """
+    _npts = int(npts)
+    if _npts != npts:
+        raise ValueError("npts must be integer")
+    if _npts < 2:
+        raise ValueError("npts must be >= 2")
+
+    x = np.linspace(-np.pi, 0, _npts)
+    return np.cos(x)
+
+
 #
 # Chebyshev series class
 #

Modified: branches/1.5.x/numpy/polynomial/tests/test_chebyshev.py
===================================================================
--- branches/1.5.x/numpy/polynomial/tests/test_chebyshev.py	2010-08-15 21:06:29 UTC (rev 8642)
+++ branches/1.5.x/numpy/polynomial/tests/test_chebyshev.py	2010-08-15 21:12:27 UTC (rev 8643)
@@ -345,7 +345,40 @@
         for i in range(10) :
             assert_equal(ch.poly2cheb(Tlist[i]), [0]*i + [1])
 
+    def test_chebpts1(self):
+        #test exceptions
+        yield assert_raises(ValueError, ch.chebpts1, 1.5)
+        yield assert_raises(ValueError, ch.chebpts1, 0)
 
+        #test points
+        tgt = [0]
+        yield assert_almost_equal(ch.chebpts1(1), tgt)
+        tgt = [-0.70710678118654746, 0.70710678118654746]
+        yield assert_almost_equal(ch.chebpts1(2), tgt)
+        tgt = [-0.86602540378443871, 0, 0.86602540378443871]
+        yield assert_almost_equal(ch.chebpts1(3), tgt)
+        tgt = [-0.9238795325, -0.3826834323,  0.3826834323,  0.9238795325]
+        yield assert_almost_equal(ch.chebpts1(4), tgt)
+
+
+    def test_chebpts2(self):
+        #test exceptions
+        yield assert_raises(ValueError, ch.chebpts2, 1.5)
+        yield assert_raises(ValueError, ch.chebpts2, 1)
+
+        #test points
+        tgt = [-1, 1]
+        yield assert_almost_equal(ch.chebpts2(2), tgt)
+        tgt = [-1, 0, 1]
+        yield assert_almost_equal(ch.chebpts2(3), tgt)
+        tgt = [-1 -0.5, .5, 1]
+        yield assert_almost_equal(ch.chebpts2(4), tgt)
+        tgt = [-1.0, -0.707106781187, 0, 0.707106781187, 1.0]
+        yield assert_almost_equal(ch.chebpts2(5), tgt)
+
+
+
+
 class TestChebyshevClass(TestCase) :
 
     p1 = ch.Chebyshev([1,2,3])




More information about the Numpy-svn mailing list