Exemplo n.º 1
0
    def test_derivative(self):
        '''Tests derivative of functions of Measurement objects
        '''
        x = e.Measurement(3, 0.4)
        y = e.Measurement(12, 1)

        self.assertEqual((x+y).get_derivative(y), 1)
        self.assertEqual((x-y).get_derivative(x), 1)
        self.assertEqual((x*y).get_derivative(y), x.mean)
        self.assertEqual((x/y).get_derivative(x), 1/y.mean)
        self.assertEqual((x**y).get_derivative(x), y.mean*x.mean**(y.mean-1))
        self.assertEqual(e.sin(x).get_derivative(x), m.cos(x.mean))
        self.assertEqual(e.cos(x).get_derivative(x), -m.sin(x.mean))
        self.assertEqual(e.tan(x).get_derivative(x), m.cos(x.mean)**-2)
        self.assertEqual(e.exp(x).get_derivative(x), m.exp(x.mean))
Exemplo n.º 2
0
def test4():
    '''Test of derivative method.
    '''
    x = e.Measurement(3, 0.4)
    y = e.Measurement(12, 1)

    assert (x+y).get_derivative(y) == 1
    assert (x-y).get_derivative(x) == 1
    assert (x*y).get_derivative(y) == x.mean
    assert (x/y).get_derivative(x) == 1/y.mean
    assert (x**y).get_derivative(x) == y.mean*x.mean**(y.mean-1)
    assert e.sin(x).get_derivative(x) == m.cos(x.mean)
    assert e.cos(x).get_derivative(x) == -m.sin(x.mean)
    assert e.tan(x).get_derivative(x) == m.cos(x.mean)**-2
    assert e.exp(x).get_derivative(x) == m.exp(x.mean)
Exemplo n.º 3
0
    def test_derivative(self):
        '''Tests derivative of functions of Measurement objects
        '''
        x = e.Measurement(3, 0.4)
        y = e.Measurement(12, 1)

        self.assertEqual((x + y).get_derivative(y), 1)
        self.assertEqual((x - y).get_derivative(x), 1)
        self.assertEqual((x * y).get_derivative(y), x.mean)
        self.assertEqual((x / y).get_derivative(x), 1 / y.mean)
        self.assertEqual((x**y).get_derivative(x),
                         y.mean * x.mean**(y.mean - 1))
        self.assertEqual(e.sin(x).get_derivative(x), m.cos(x.mean))
        self.assertEqual(e.cos(x).get_derivative(x), -m.sin(x.mean))
        self.assertEqual(e.tan(x).get_derivative(x), m.cos(x.mean)**-2)
        self.assertEqual(e.exp(x).get_derivative(x), m.exp(x.mean))
Exemplo n.º 4
0
    def test_array_functions(self):
        '''Tests mathematical functions on Measurement objects
        '''
        x = e.MeasurementArray([4, 9, 2], error = [0.1, 0.2, 0.3])
        y = e.MeasurementArray([0.3, 0.56, 0.2], error = 0.01)

        self.assertEqual(e.sin(x).means.tolist(), np.sin(x.means).tolist())
        self.assertEqual(e.cos(x).means.tolist(), np.cos(x.means).tolist())
        self.assertEqual(e.tan(x).means.tolist(), np.tan(x.means).tolist())
        self.assertEqual(e.csc(x).means.tolist(), (1/np.sin(x.means)).tolist())
        self.assertEqual(e.sec(x).means.tolist(), (1/np.cos(x.means)).tolist())
        self.assertEqual(e.cot(x).means.tolist(), (1/np.tan(x.means)).tolist())
        self.assertEqual(e.exp(x).means.tolist(), np.exp(x.means).tolist())
        self.assertEqual(e.log(x).means.tolist(), np.log(x.means).tolist())
        self.assertEqual(e.asin(y).means.tolist(), np.arcsin(y.means).tolist())
        self.assertEqual(e.acos(y).means.tolist(), np.arccos(y.means).tolist())
        self.assertEqual(e.atan(x).means.tolist(), np.arctan(x.means).tolist())
Exemplo n.º 5
0
    def test_measurement_functions(self):
        '''Tests mathematical functions on Measurement objects
        '''
        x = e.Measurement(3.2, 0.01)
        y = e.Measurement(0.23, 0.04)

        self.assertEqual(e.sin(x), m.sin(x.mean))
        self.assertEqual(e.cos(x), m.cos(x.mean))
        self.assertEqual(e.tan(x), m.tan(x.mean))
        self.assertEqual(e.csc(x), 1/m.sin(x.mean))
        self.assertEqual(e.sec(x), 1/m.cos(x.mean))
        self.assertEqual(e.cot(x), 1/m.tan(x.mean))
        self.assertEqual(e.exp(x), m.exp(x.mean))
        self.assertEqual(e.log(x), m.log(x.mean))
        self.assertEqual(e.asin(y), m.asin(y.mean))
        self.assertEqual(e.acos(y), m.acos(y.mean))
        self.assertEqual(e.atan(x), m.atan(x.mean))
Exemplo n.º 6
0
    def test_measurement_functions(self):
        '''Tests mathematical functions on Measurement objects
        '''
        x = e.Measurement(3.2, 0.01)
        y = e.Measurement(0.23, 0.04)

        self.assertEqual(e.sin(x), m.sin(x.mean))
        self.assertEqual(e.cos(x), m.cos(x.mean))
        self.assertEqual(e.tan(x), m.tan(x.mean))
        self.assertEqual(e.csc(x), 1 / m.sin(x.mean))
        self.assertEqual(e.sec(x), 1 / m.cos(x.mean))
        self.assertEqual(e.cot(x), 1 / m.tan(x.mean))
        self.assertEqual(e.exp(x), m.exp(x.mean))
        self.assertEqual(e.log(x), m.log(x.mean))
        self.assertEqual(e.asin(y), m.asin(y.mean))
        self.assertEqual(e.acos(y), m.acos(y.mean))
        self.assertEqual(e.atan(x), m.atan(x.mean))
Exemplo n.º 7
0
def test2():
    '''Test of elementary functions.
    '''
    x = e.Measurement(10, 1)
    y = e.Measurement(0, 0.1)

    assert e.sin(x) == m.sin(x.mean)
    assert e.cos(x) == m.cos(x.mean)
    assert e.tan(x) == m.tan(x.mean)
    assert e.csc(x) == 1/m.sin(x.mean)
    assert e.sec(x) == 1/m.cos(x.mean)
    assert e.cot(x) == 1/m.tan(x.mean)
    assert e.exp(x) == m.exp(x.mean)
    assert e.log(x) == m.log(x.mean)
    assert e.asin(y) == m.asin(y.mean)
    assert e.acos(y) == m.acos(y.mean)
    assert e.atan(x) == m.atan(x.mean)
Exemplo n.º 8
0
    def test_array_functions(self):
        '''Tests mathematical functions on Measurement objects
        '''
        x = e.MeasurementArray([4, 9, 2], error=[0.1, 0.2, 0.3])
        y = e.MeasurementArray([0.3, 0.56, 0.2], error=0.01)

        self.assertEqual(e.sin(x).means.tolist(), np.sin(x.means).tolist())
        self.assertEqual(e.cos(x).means.tolist(), np.cos(x.means).tolist())
        self.assertEqual(e.tan(x).means.tolist(), np.tan(x.means).tolist())
        self.assertEqual(
            e.csc(x).means.tolist(), (1 / np.sin(x.means)).tolist())
        self.assertEqual(
            e.sec(x).means.tolist(), (1 / np.cos(x.means)).tolist())
        self.assertEqual(
            e.cot(x).means.tolist(), (1 / np.tan(x.means)).tolist())
        self.assertEqual(e.exp(x).means.tolist(), np.exp(x.means).tolist())
        self.assertEqual(e.log(x).means.tolist(), np.log(x.means).tolist())
        self.assertEqual(e.asin(y).means.tolist(), np.arcsin(y.means).tolist())
        self.assertEqual(e.acos(y).means.tolist(), np.arccos(y.means).tolist())
        self.assertEqual(e.atan(x).means.tolist(), np.arctan(x.means).tolist())