import numpy as np import matplotlib.pyplot as plt import matplotlib.animation as animation import modules.rollingball as RB import AutoDiff_CKMZ.modules.AutoDiff as AD from time import time function_list = [lambda x: AD.sin(x), lambda x: AD.exp(x), lambda x: x * AD.sin(x), lambda x: - AD.log(x), lambda x: AD.sinh(x), lambda x: AD.exp(AD.cos(x)), lambda x: 2 ** x, lambda x: 1 / AD.tan(x), lambda x: AD.sin(x) / x, lambda x: x ** 2] derivative_list = [lambda x: np.cos(x), lambda x: np.exp(x), lambda x: np.sin(x) + x * np.cos(x), lambda x: -1 / x, lambda x: np.cosh(x), lambda x: - np.exp(np.cos(x)) * np.sin(x), lambda x: 2 ** x * np.log(2), lambda x: - 1 / np.sin(x) ** 2, lambda x: (x * np.cos(x) - np.sin(x)) / x ** 2, lambda x: 2 * x] class function():
def test_tan_exp_div_neg(): f = -AD.tan(x1) / AD.exp(x1) assert tol > abs(f.x - 0.29571298878) assert tol > abs(f.dx - -1.077192940578)
def test_multivariate(): f = x3[0] * AD.exp(3 * x3[1]) assert f.dx[0] == 1 assert f.dx[1] == 6
def test_exp(): f = AD.exp(x1) assert f.x == np.exp(2) assert f.dx == np.exp(2) f = AD.exp(2) assert f == np.exp(2)