Пример #1
0
    def test_inverse_functions(self):
        from pyaudi import gdual_double as gdual
        from pyaudi import sinh, cosh, tanh
        from pyaudi import asinh, acosh, atanh
        from pyaudi import sin, cos, tan
        from pyaudi import asin, acos, atan

        x = gdual(1.1, "x", 6)
        y = gdual(1.2, "y", 6)
        p1 = 1. / (x + y)

        self.assertTrue((cos(acos(p1)) - p1).is_zero(1e-12))
        self.assertTrue((acos(cos(p1)) - p1).is_zero(1e-12))

        self.assertTrue((sin(asin(p1)) - p1).is_zero(1e-12))
        self.assertTrue((asin(sin(p1)) - p1).is_zero(1e-12))

        self.assertTrue((tan(atan(p1)) - p1).is_zero(1e-12))
        self.assertTrue((atan(tan(p1)) - p1).is_zero(1e-12))

        self.assertTrue((cosh(acosh(p1)) - p1).is_zero(1e-12))
        self.assertTrue((acosh(cosh(p1)) - p1).is_zero(1e-12))

        self.assertTrue((sinh(asinh(p1)) - p1).is_zero(1e-12))
        self.assertTrue((asinh(sinh(p1)) - p1).is_zero(1e-12))

        self.assertTrue((tanh(atanh(p1)) - p1).is_zero(1e-12))
        self.assertTrue((atanh(tanh(p1)) - p1).is_zero(1e-12))
Пример #2
0
    def test_inverse_functions(self):
        from pyaudi import gdual_double as gdual
        from pyaudi import sinh, cosh, tanh
        from pyaudi import asinh, acosh, atanh
        from pyaudi import sin, cos, tan
        from pyaudi import asin, acos, atan

        x = gdual(1.1, "x",6);
        y = gdual(1.2, "y",6);
        p1 = 1. / (x + y);

        self.assertTrue((cos(acos(p1))-p1).is_zero(1e-12))
        self.assertTrue((acos(cos(p1))-p1).is_zero(1e-12))

        self.assertTrue((sin(asin(p1))-p1).is_zero(1e-12))
        self.assertTrue((asin(sin(p1))-p1).is_zero(1e-12))

        self.assertTrue((tan(atan(p1))-p1).is_zero(1e-12))
        self.assertTrue((atan(tan(p1))-p1).is_zero(1e-12))

        self.assertTrue((cosh(acosh(p1))-p1).is_zero(1e-12))
        self.assertTrue((acosh(cosh(p1))-p1).is_zero(1e-12))

        self.assertTrue((sinh(asinh(p1))-p1).is_zero(1e-12))
        self.assertTrue((asinh(sinh(p1))-p1).is_zero(1e-12))

        self.assertTrue((tanh(atanh(p1))-p1).is_zero(1e-12))
        self.assertTrue((atanh(tanh(p1))-p1).is_zero(1e-12))
Пример #3
0
    def test_map_inversion(self):
        from pyaudi import gdual_double as gdual
        from pyaudi import sin, exp, invert_map, cos

        x = gdual(0., "x", 11)
        f = 1. / (1 + exp(sin(x) + 1. / (x + 1))) + x
        g = invert_map([f], False)[0]
        dx = g.evaluate({"dp0": 0.01})
        newf = f.evaluate({"dx": dx})
        self.assertAlmostEqual(newf, f.constant_cf + 0.01, delta=1e-10)

        x = gdual(0, "x", 4)
        y = gdual(0, "y", 4)
        f0 = 1. / (1 + exp(sin(x * y) + 1. / (x + 1))) + x - y
        f1 = 1. / (1 + exp(cos(x * y) + 1. / (y + 1))) + x + y
        g0, g1 = invert_map([f0, f1], False)
        dx = g0.evaluate({"dp0": 0.01, "dp1": -0.02})
        dy = g1.evaluate({"dp0": 0.01, "dp1": -0.02})
        newf0 = f0.evaluate({"dx": dx, "dy": dy})
        newf1 = f1.evaluate({"dx": dx, "dy": dy})
        self.assertAlmostEqual(newf0, f0.constant_cf + 0.01, delta=1e-6)
        self.assertAlmostEqual(newf1, f1.constant_cf - 0.02, delta=1e-6)

        # We test the API
        g0, g1 = invert_map(map=[f0, f1], verbose=False)
        g0, g1 = invert_map(map=[f0, f1])
        g0, g1 = invert_map([f0, f1])
Пример #4
0
 def test_function_methods(self):
     from pyaudi import gdual_double as gdual
     from pyaudi import exp, log, sin, cos
     x = gdual(0.5, "x", 11)
     self.assertEqual(exp(x), x.exp())
     self.assertEqual(log(x), x.log())
     self.assertEqual(sin(x), x.sin())
     self.assertEqual(cos(x), x.cos())
Пример #5
0
    def test_tan(self):
        from pyaudi import gdual_double as gdual
        from pyaudi import sin, cos, tan

        x = gdual(2.3, "x", 10)
        y = gdual(1.5, "y", 10)

        p1 = x + y
        self.assertTrue((tan(p1) - sin(p1) / cos(p1)).is_zero(1e-12))
Пример #6
0
    def test_tan(self):
        from pyaudi import gdual_double as gdual
        from pyaudi import sin, cos, tan

        x = gdual(2.3, "x",10);
        y = gdual(1.5, "y",10);

        p1 = x + y;
        self.assertTrue((tan(p1) - sin(p1) / cos(p1)).is_zero(1e-12))
Пример #7
0
def some_complex_irrational_f(x, y, z):
    from pyaudi import exp, log, cos, sin, tan, sqrt, cbrt, cos, sin, tan, acos, asin, atan, cosh, sinh, tanh, acosh, asinh, atanh
    from pyaudi import abs as gd_abs
    from pyaudi import sin_and_cos, sinh_and_cosh
    f = (x + y + z) / 10.
    retval = exp(f) + log(f) + f**2 + sqrt(f) + cbrt(f) + cos(f) + sin(f)
    retval += tan(f) + acos(f) + asin(f) + atan(f) + cosh(f) + sinh(f)
    retval += tanh(f) + acosh(f) + asinh(f) + atanh(f)
    a = sin_and_cos(f)
    b = sinh_and_cosh(f)
    retval += a[0] + a[1] + b[0] + b[1]
    return retval
Пример #8
0
def some_complex_irrational_f(x,y,z):
    from pyaudi import exp, log, cos, sin, tan, sqrt, cbrt, cos, sin, tan, acos, asin, atan, cosh, sinh, tanh, acosh, asinh, atanh
    from pyaudi import abs as gd_abs
    from pyaudi import sin_and_cos, sinh_and_cosh
    f = (x+y+z) / 10.
    retval = exp(f) + log(f) + f**2 + sqrt(f) + cbrt(f) + cos(f) + sin(f)
    retval += tan(f) + acos(f) + asin(f) + atan(f)  + cosh(f) + sinh(f)
    retval += tanh(f) + acosh(f) + asinh(f) + atanh(f)
    a = sin_and_cos(f)
    b = sinh_and_cosh(f)
    retval+=a[0]+a[1]+b[0]+b[1]
    return retval
Пример #9
0
def d_state_bebop(state, controls, mass=0.38905):
    [x, vx, z, vz, theta] = state
    [u1, u2] = controls

    g = 9.81

    d_x = vx
    d_vx = u1 * sin(theta) / mass - vx / 2
    d_z = vz
    d_vz = u1 * cos(theta) / mass - g - vz / 2
    d_theta = u2

    return np.array([d_x, d_vx, d_z, d_vz, d_theta])
Пример #10
0
def d_state(state, controls, mass=1):
    [x, vx, z, vz, theta] = state
    [u1, u2] = controls

    g = 9.81

    d_x = vx
    d_vx = u1 * sin(theta) / mass
    d_z = vz
    d_vz = u1 * cos(theta) / mass - g
    d_theta = u2

    return np.array([d_x, d_vx, d_z, d_vz, d_theta])
Пример #11
0
    def test_sin_and_cos(self):
        from pyaudi import gdual_double as gdual
        from pyaudi import sin, cos, sin_and_cos
        x = gdual(2.3, "x", 8)
        y = gdual(1.5, "y", 8)

        p1 = x + y

        self.assertTrue((sin(2 * p1) - 2 * sin(p1) * cos(p1)).is_zero(1e-12))
        self.assertTrue(
            (cos(2 * p1) - 1 + 2 * sin(p1) * sin(p1)).is_zero(1e-12))
        self.assertTrue(
            (cos(2 * p1) + 1 - 2 * cos(p1) * cos(p1)).is_zero(1e-12))
        self.assertTrue((cos(2 * p1) - cos(p1) * cos(p1) +
                         sin(p1) * sin(p1)).is_zero(1e-12))
        self.assertTrue(
            (sin(p1) * sin(p1) + cos(p1) * cos(p1) - 1).is_zero(1e-12))

        res = sin_and_cos(p1)
        self.assertTrue((res[0] - sin(p1)).is_zero(1e-12))
        self.assertTrue((res[1] - cos(p1)).is_zero(1e-12))
Пример #12
0
 def do(self, x1, x2):
     import pyaudi as pd
     res = x1.cos()
     assert (res == pd.cos(x1))
Пример #13
0
    def test_sin_and_cos(self):
        from pyaudi import gdual_double as gdual
        from pyaudi import sin, cos, sin_and_cos
        x = gdual(2.3, "x",8);
        y = gdual(1.5, "y",8);

        p1 = x + y;

        self.assertTrue((sin(2*p1) - 2 * sin(p1) * cos(p1)).is_zero(1e-12))
        self.assertTrue((cos(2*p1) - 1 + 2*sin(p1)*sin(p1)).is_zero(1e-12))
        self.assertTrue((cos(2*p1) + 1 - 2*cos(p1)*cos(p1)).is_zero(1e-12))
        self.assertTrue((cos(2*p1) - cos(p1)*cos(p1) + sin(p1) * sin(p1)).is_zero(1e-12))
        self.assertTrue((sin(p1)*sin(p1) + cos(p1)*cos(p1) - 1).is_zero(1e-12))

        res = sin_and_cos(p1);
        self.assertTrue((res[0] - sin(p1)).is_zero(1e-12))
        self.assertTrue((res[1] - cos(p1)).is_zero(1e-12))