Beispiel #1
0
 def test_div_diff(self):
     x = X()
     f = Div(x, Add(Mul(x, x), Number(1)))  # f(x) = x / (x**2 + 1)
     self.assertAlmostEqual(f.diff().eval(1), 0)
     self.assertAlmostEqual(f.diff().eval(2), -3 / 25)
Beispiel #2
0
 def test_div(self):
     x = X()
     f = Div(x, Add(Mul(x, x), Number(1)))  # f(x) = x / (x**2 + 1)
     self.assertAlmostEqual(f.eval(2), 0.4)
Beispiel #3
0
 def test_sub_diff(self):
     x = X()
     f = Sub(Mul(x, x), Mul(Number(2), x))  # f(x) = x**2 - 2x
     self.assertEqual(f.diff().eval(2), 2)
Beispiel #4
0
 def test_xx_3x_2_diff(self):
     x = X()
     f = Add(Add(Mul(x, x), Mul(Number(3), x)), Number(2))
     # f(x) = x**2 + 3x + 2
     self.assertEqual(f.diff().eval(10), 23)
Beispiel #5
0
 def test_2x_3_diff(self):
     f = Add(Mul(Number(2), X()), Number(3))  # f(x) = 2x + 3
     self.assertEqual(f.diff().eval(100), 2)
Beispiel #6
0
 def test_2x_3_eval(self):
     f = Add(Mul(Number(2), X()), Number(3))  # f(x) = 2x + 3
     self.assertEqual(f.eval(10), 23)