def test_raise_error(self):
     x = np.linspace(-1, 1, 9)
     y = np.sin(x)
     dy = np.cos(x)
     p, resid, rms, maxresid = chebyUtils.chebfit(x, y, dy, nPoly=4)
     with self.assertRaises(RuntimeError):
         chebyUtils.chebeval(np.linspace(-1, 1, 17), p, interval=[1, 2, 3])
 def test_eval(self):
     x = np.linspace(-1, 1, 9)
     y = np.sin(x)
     dy = np.cos(x)
     p, resid, rms, maxresid = chebyUtils.chebfit(x, y, dy, nPoly=4)
     yy_wVel, vv = chebyUtils.chebeval(np.linspace(-1, 1, 17), p)
     yy_woutVel, vv = chebyUtils.chebeval(np.linspace(-1, 1, 17), p, doVelocity=False)
     self.assertTrue(np.allclose(yy_woutVel, yy_wVel))
 def test_ends_locked(self):
     x = np.linspace(-1, 1, 9)
     y = np.sin(x)
     dy = np.cos(x)
     for polynomial in range(4, 10):
         p, resid, rms, maxresid = chebyUtils.chebfit(x, y, dy, nPoly=4)
         yy, vv = chebyUtils.chebeval(np.linspace(-1, 1, 17), p)
         self.assertAlmostEqual(yy[0], y[0], places=13)
         self.assertAlmostEqual(yy[-1], y[-1], places=13)
         self.assertAlmostEqual(vv[0], dy[0], places=13)
         self.assertAlmostEqual(vv[-1], dy[-1], places=13)
예제 #4
0
 def test_accuracy(self):
     """If nPoly is  greater than number of values being fit, then fit should be exact.
     """
     x = np.linspace(0, np.pi, 9)
     y = np.sin(x)
     dy = np.cos(x)
     p, resid, rms, maxresid = chebyUtils.chebfit(x, y, dy, nPoly=16)
     yy, vv = chebyUtils.chebeval(x, p, interval=np.array([0, np.pi]))
     self.assertTrue(np.allclose(yy, y, rtol=1e-13))
     self.assertTrue(np.allclose(vv, dy, rtol=1e-13))
     self.assertLess(np.sum(resid), 1e-13)
 def test_accuracy_prefit_c1c2(self):
     """If nPoly is  greater than number of values being fit, then fit should be exact.
     """
     NPOINTS = 8
     NPOLY = 16
     x = np.linspace(0, np.pi, NPOINTS + 1)
     y = np.sin(x)
     dy = np.cos(x)
     xmatrix, dxmatrix = chebyUtils.makeChebMatrix(NPOINTS + 1, NPOLY)
     p, resid, rms, maxresid = chebyUtils.chebfit(x, y, dy, xMultiplier=xmatrix, dxMultiplier=dxmatrix, nPoly=NPOLY)
     yy, vv = chebyUtils.chebeval(x, p, interval=np.array([0, np.pi]))
     self.assertTrue(np.allclose(yy, y, rtol=1e-13))
     self.assertTrue(np.allclose(vv, dy, rtol=1e-13))
     self.assertLess(np.sum(resid), 1e-13)