Example #1
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
Example #2
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
Example #3
0
    def test_cbrt(self):
        from pyaudi import gdual_double as gdual
        from pyaudi import cbrt
        x = gdual(2.3, "x",3);
        y = gdual(1.5, "y",3);

        p1 = x*x*y - x*y*x*x*x + 3*y*y*y*y*x*y*x;  # positive p0
        p2 = x*x*y - x*y*x*x*x - 3*y*y*y*y*x*y*x;  # negative coefficient
        self.assertTrue((cbrt(p1)*cbrt(p1)*cbrt(p1) - p1).is_zero(1e-12))
        self.assertTrue((cbrt(p2)*cbrt(p2)*cbrt(p2) - p2).is_zero(1e-12))
Example #4
0
    def test_cbrt(self):
        from pyaudi import gdual_double as gdual
        from pyaudi import cbrt
        x = gdual(2.3, "x", 3)
        y = gdual(1.5, "y", 3)

        p1 = x * x * y - x * y * x * x * x + 3 * \
            y * y * y * y * x * y * x  # positive p0
        p2 = x * x * y - x * y * x * x * x - 3 * y * \
            y * y * y * x * y * x  # negative coefficient
        self.assertTrue((cbrt(p1) * cbrt(p1) * cbrt(p1) - p1).is_zero(1e-12))
        self.assertTrue((cbrt(p2) * cbrt(p2) * cbrt(p2) - p2).is_zero(1e-12))
Example #5
0
from pyaudi import gdual_double as gdual
from pyaudi import exp, log, cbrt

# We want to compute the Taylor expansion of a function f (and thus all derivatives) at x=2, y=3
# 1 - Define the generalized dual numbers (7 is the truncation order, i.e. the maximum order of derivation we will need)

x = gdual(2, "x", 7)
y = gdual(3, "y", 7)

# 2 - Compute your function as usual
f = exp(x * x + cbrt(y) / log(x * y))

# 3 - Inspect the results (this does not require any more computations)
print("Taylor polynomial: " +
      str(f))  # This is the Taylor expansion of f (truncated at the 7th order)
print("Derivative value [1,0]: " + str(f.get_derivative(
    [1, 0])))  # This is the value of the derivative (d / dx)
print("Derivative value [4,3]: " + str(f.get_derivative(
    [4, 3])))  # This is the value of the mixed derivative (d^7 / dx^4dy^3)

# 4 - Using the dictionary interface (note the presence of the "d" before all variables)
print("Derivative value [1,0]: " + str(f.get_derivative(
    {"dx": 1})))  # This is the value of the derivative (d / dx)
print("Derivative value [4,3]: " + str(f.get_derivative({
    "dx": 4,
    "dy": 3
})))  # This is the value of the mixed derivative (d^7 / dx^4dy^3)
Example #6
0
from pyaudi import gdual_double as gdual
from pyaudi import exp, log, cbrt

# We want to compute the Taylor expansion of a function f (and thus all derivatives) at x=2, y=3
# 1 - Define the generalized dual numbers (7 is the truncation order, i.e. the maximum order of derivation we will need)

x = gdual(2, "x", 7);
y = gdual(3, "y", 7);

# 2 - Compute your function as usual
f = exp(x*x + cbrt(y) / log(x*y));

# 3 - Inspect the results (this does not require any more computations)
print("Taylor polynomial: " + str(f))                          # This is the Taylor expansion of f (truncated at the 7th order)
print("Derivative value [1,0]: " + str(f.get_derivative([1,0])))     # This is the value of the derivative (d / dx)
print("Derivative value [4,3]: " + str(f.get_derivative([4,3])))     # This is the value of the mixed derivative (d^7 / dx^4dy^3)

# 4 - Using the dictionary interface (note the presence of the "d" before all variables)
print("Derivative value [1,0]: " + str(f.get_derivative({"dx":1})))     # This is the value of the derivative (d / dx)
print("Derivative value [4,3]: " + str(f.get_derivative({"dx":4, "dy":3})))     # This is the value of the mixed derivative (d^7 / dx^4dy^3)