def test_simpleFunc9(): func14_val = lambda x: np.sin(x) / (3 - 2 * np.cos(x)) func14_der = lambda x: (-2 + 3 * np.cos(x)) / (3 - 2 * np.cos(x))**2 a14 = np.pi / 4 x14 = ad.variable(a14) f14 = ad.sin(x14) / (3 - 2 * ad.cos(x14)) assert np.isclose(f14.val, func14_val(a14)) assert np.isclose(f14.der, func14_der(a14))
def test_simpleFunc6(): func11_val = lambda x: ((x**3) + 4 * x) / np.sin(3) func11_der = lambda x: ((3 * x**2) + 4) / np.sin(3) a11 = 6 x11 = ad.variable(a11) f11 = ((x11**3) + 4 * x11) / ad.sin(3) assert f11.val == func11_val(a11) assert f11.der == func11_der(a11)
def test_simpleFunc3(): def f1(x): return np.sin(x) / 3 + np.cos(x) / x def f1_dx(x): return -np.sin(x) / x - np.cos(x) / x**2 + np.cos(x) / 3 x1 = ad.variable(83) f = ad.sin(x1) / 3 + ad.cos(x1) / x1 assert f.val == f1(83) assert f.der == f1_dx(83)
def test_sin(): # Sine of variable: f1 = ad.sin(np.pi) assert np.isclose(f1.val, 0.0) assert np.isclose(f1.der, 0.0) # Sine of variable: x2 = ad.variable(np.pi) f2 = ad.sin(x2) assert np.isclose(f2.val, 0.0) assert np.isclose(f2.der, -1.0) # Sine of variable times constant: x3 = ad.variable(0.0) f3 = ad.sin(x3) * 5 assert np.isclose(f3.val, 0.0) assert np.isclose(f3.der, 5.0) # Sine of constant times variable: x4 = ad.variable(np.pi) f4 = ad.sin(x4 * 2) assert np.isclose(f4.val, 0.0) assert np.isclose(f4.der, 2.0)
def func1(x): f1 = (ad.sin(x))**2 return f1
def func5(x, y): f1 = x * y + ad.cos(x) f2 = x * y + ad.sin(y) return [f1, f2]
def root_finding(a): return ad.sin(a)