Exemple #1
0
 def test_mononom(self):
     """Test with a constant, linear, quadratic and cubic
     function."""
     f = lambda w,x,y,z : x + y**2 + z**3
     dfw = deriv(f, 0, .01) # 0
     self.assertAlmostEqual(dfw(1,1,1,1), 0.)
     self.assertAlmostEqual(dfw(1,2,1,1), 0.)
     self.assertAlmostEqual(dfw(1,2,2,1), 0.)
     self.assertAlmostEqual(dfw(1,2,1,2), 0.)
     dfx = deriv(f, 1, .01) # 1 
     self.assertAlmostEqual(dfx(1,1,1,1), 1.)
     self.assertAlmostEqual(dfx(1,2,1,1), 1.)
     self.assertAlmostEqual(dfx(1,2,1,2), 1.)
     dfy = deriv(f, 2, .01) # 2*y
     self.assertAlmostEqual(dfy(1,1,1,1), 2.)
     self.assertAlmostEqual(dfy(1,1,2,1), 4.)
     dfz = deriv(f, 3, .0001) # 3 * z**2
     self.assertAlmostEqual(dfz(1,1,1,1), 3.)
     self.assertAlmostEqual(dfz(1,1,1,2), 12.)
Exemple #2
0
 def test_mononom(self):
     """Test with a constant, linear, quadratic and cubic
     function."""
     f = lambda w, x, y, z: x + y**2 + z**3
     dfw = deriv(f, 0, .01)  # 0
     self.assertAlmostEqual(dfw(1, 1, 1, 1), 0.)
     self.assertAlmostEqual(dfw(1, 2, 1, 1), 0.)
     self.assertAlmostEqual(dfw(1, 2, 2, 1), 0.)
     self.assertAlmostEqual(dfw(1, 2, 1, 2), 0.)
     dfx = deriv(f, 1, .01)  # 1
     self.assertAlmostEqual(dfx(1, 1, 1, 1), 1.)
     self.assertAlmostEqual(dfx(1, 2, 1, 1), 1.)
     self.assertAlmostEqual(dfx(1, 2, 1, 2), 1.)
     dfy = deriv(f, 2, .01)  # 2*y
     self.assertAlmostEqual(dfy(1, 1, 1, 1), 2.)
     self.assertAlmostEqual(dfy(1, 1, 2, 1), 4.)
     dfz = deriv(f, 3, .0001)  # 3 * z**2
     self.assertAlmostEqual(dfz(1, 1, 1, 1), 3.)
     self.assertAlmostEqual(dfz(1, 1, 1, 2), 12.)
Exemple #3
0
 def test_sin(self):
     """Test with the sine function."""
     f = lambda x : sin(x)
     df = deriv(f, 0, .00001)
     for x in np.linspace(0,2,20):
         self.assertAlmostEqual(df(x), cos(x))
Exemple #4
0
 def test_sin(self):
     """Test with the sine function."""
     f = lambda x: sin(x)
     df = deriv(f, 0, .00001)
     for x in np.linspace(0, 2, 20):
         self.assertAlmostEqual(df(x), cos(x))