def Demo_gradient(x): x=DualNumber(x); y=-EF.Sin(x)*EF.Cos(x)*EF.Tan(x)+EF.Exp(x)*EF.Log(x)*EF.Sqrt(x)*2 return y.der #y=sin(x)cos(x)tan(x)-2exp(x)log(x)sqrt(x)
def rm_test_exp(): Test_Dual_Number_1 = DualNumber(1,Reverse=True) assert EF.Exp(Test_Dual_Number_1).val == np.exp(1) and EF.Exp(Test_Dual_Number_1).der == 0
def Given_function(x): x = DualNumber(x) y = EF.Sin(x) * EF.Cos(x) * EF.Tan(x) - EF.Exp(x) * EF.Log(x) * EF.Sqrt( x) * 2 return y #y=sin(x)cos(x)tan(x)-2exp(x)log(x)sqrt(x)
def test_exp(): Test_Dual_Number_1 = DualNumber(1) assert EF.Exp(Test_Dual_Number_1).val == np.exp(1) and EF.Exp(Test_Dual_Number_1).der == np.exp(1) Test_Dual_Number_1 = 1 assert EF.Exp(Test_Dual_Number_1).val == np.exp(1) and EF.Exp(Test_Dual_Number_1).der == 0