public void MakeExpressionTest() { Func <double, double> expected = (double x) => - Math.Pow(x, 3) / 6; Func <double, double> actual = TaylorSeries.MakeExpression(3, 0); Assert.AreEqual(actual(5), expected(5)); }
public void TestForCalculateExp_WhenfirstArgumentIsNegative() { var e = new TaylorSeries(); var actual = e.CalculateExp(-2, 4); var expected = 1 - 2.0 / 3; Assert.AreEqual(expected, actual); }
public void TestForCalculateExp_WhenfirstArgumentIsZero() { var e = new TaylorSeries(); var actual = e.CalculateExp(0, 3); var expected = 1; Assert.AreEqual(expected, actual); }
public void TestForCalculateExp_WhenBothArgumentsArePositive() { var e = new TaylorSeries(); var actual = e.CalculateExp(4, 3); var expected = 13 + 64.0 / 6; Assert.AreEqual(expected, actual); }
public void DetermineSinSpanMaxTest() { Function sinFunction = new Function("sinx"); Func <double, double> series = TaylorSeries.MakeTaylorSeries(4, 0, 1, 0); var maxspan = TaylorSeries.DetermineSinSpanMax(sinFunction.ParsedFunc, series, 0); Assert.AreEqual(3, maxspan); }
public void MakeTaylorSeriesTest() { var actual = TaylorSeries.MakeTaylorSeries(4, 1, 1, 0); Func <double, double> expected = (double d) => Math.Sin(1) * Math.Pow(d - 1, 0) / Function.Factorial(0) + Math.Cos(1) * Math.Pow(d - 1, 1) / Function.Factorial(1) - Math.Sin(1) * Math.Pow(d - 1, 2) / Function.Factorial(2) - Math.Cos(1) * Math.Pow(d - 1, 3) / Function.Factorial(3); Assert.AreEqual(actual(1), expected(1)); }
public void DerivativeSectionTest() { var actual1 = TaylorSeries.DerivativeSection(1); var actual2 = TaylorSeries.DerivativeSection(2); var actual3 = TaylorSeries.DerivativeSection(3); var actual4 = TaylorSeries.DerivativeSection(4); Assert.AreEqual(1, actual1(0)); Assert.AreEqual(0, actual2(0)); Assert.AreEqual(-1, actual3(0)); Assert.AreEqual(0, actual4(0)); }
public void CalculateTest() { TaylorSeries series = new TaylorSeries(Math.Sin); var answer = Math.Round(series.Calculate(2, 0, 1), 8); Assert.AreEqual(0.83333333, answer); answer = Math.Round(series.Calculate(4, 0, 1), 8); Assert.AreEqual(0.84146825, answer); answer = Math.Round(series.Calculate(3, 1, 2), 8); Assert.AreEqual(0.9610378, answer); answer = Math.Round(series.Calculate(6, 3, 5), 8); Assert.AreEqual(-0.971033, answer); answer = Math.Round(series.Calculate(3, -1, 2), 8); Assert.AreEqual(4.56605536, answer); }