示例#1
0
文件: test.py 项目: darioizzo/audi
    def test_exp_log(self):
        from pyaudi import gdual_double as gdual
        from pyaudi import exp, log
        x = gdual(2.3, "x",5);
        y = gdual(1.5, "y",5);

        p1 = x*x*y - x*y*x*x*x + 3*y*y*y*y*x*y*x;
        self.assertTrue((exp(log(p1)) - p1).is_zero(1e-10))
示例#2
0
文件: test.py 项目: darioizzo/audi
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
示例#3
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)