Exemplo n.º 1
0
 def test_te_secant(self):
     "Test Taylor expansion of secant(var)"
     x = Variable('x')
     self.assertEqual(te_secant(x, 1), 1 + x**2/2.)
     self.assertEqual(te_secant(x, 2), 1 + x**2/2. + 5*x**4/24.)
     self.assertEqual(te_secant(x, 0), 1)
     # make sure x was not modified
     self.assertEqual(x, Variable('x'))
     # try for VectorVariable too
     y = VectorVariable(3, 'y')
     self.assertEqual(te_secant(y, 1), 1 + y**2/2.)
     self.assertEqual(te_secant(y, 2), 1 + y**2/2. + 5*y**4/24.)
     self.assertEqual(te_secant(y, 0), 1)
     # make sure y was not modified
     self.assertEqual(y, VectorVariable(3, 'y'))
Exemplo n.º 2
0
 def test_te_secant(self):
     "Test Taylor expansion of secant(var)"
     x = Variable('x')
     self.assertEqual(te_secant(x, 1), 1 + x**2 / 2)
     a = te_secant(x, 2)
     b = 1 + x**2 / 2 + 5 * x**4 / 24
     self.assertTrue(
         all([abs(val) <= 1e-10 for val in (a.hmap - b.hmap).values()]))  # pylint:disable=no-member
     self.assertEqual(te_secant(x, 0), 1)
     # make sure x was not modified
     self.assertEqual(x, Variable('x'))
     # try for VectorVariable too
     y = VectorVariable(3, 'y')
     self.assertTrue(te_secant(y, 0) == 1)  # truthy bc monomial constraint
     self.assertTrue(all(te_secant(y, 1) == 1 + y**2 / 2))
     self.assertTrue(all(te_secant(y, 2) == 1 + y**2 / 2 + 5 * y**4 / 24))
     # make sure y was not modified
     self.assertEqual(y, VectorVariable(3, 'y'))
     _ = te_secant(x, 13)  # to trigger the extension
Exemplo n.º 3
0
 def test_te_secant(self):
     "Test Taylor expansion of secant(var)"
     x = Variable('x')
     self.assertEqual(te_secant(x, 1), 1 + x**2 / 2.)
     a = te_secant(x, 2)
     b = 1 + x**2 / 2. + 5 * x**4 / 24.
     self.assertTrue(
         all([abs(val) <= 1e-10 for val in (a.hmap - b.hmap).values()]))  # pylint:disable=no-member
     self.assertEqual(te_secant(x, 0), 1)
     # make sure x was not modified
     self.assertEqual(x, Variable('x'))
     # try for VectorVariable too
     y = VectorVariable(3, 'y')
     self.assertEqual(te_secant(y, 1), 1 + y**2 / 2.)
     self.assertEqual(te_secant(y, 2), 1 + y**2 / 2. + 5 * y**4 / 24.)
     self.assertEqual(te_secant(y, 0), 1)
     # make sure y was not modified
     self.assertEqual(y, VectorVariable(3, 'y'))