static void VerifyIntegrals() { string integrand = "x*x"; double startValue = -1; double endValue = 1; int iterationsNumber = 1000; string parameterName = "x"; Integral.IntegralInputParameters inputParameters = new IntegralInputParameters { IntegrandExpression = integrand, StartValue = startValue, EndValue = endValue, IterationsNumber = iterationsNumber, ParameterName = parameterName }; Integral.Integral integral = Integral.Integral.GetIntegral(CalculationType.LeftRectangle, inputParameters); double resultLeftRectangle = integral.Calculate(); double resultLeftRectangleAsync = integral.CalculateAsync(); integral = Integral.Integral.GetIntegral(CalculationType.RightRectangle, inputParameters); double resultRightRectangle = integral.Calculate(); double resultRightRectangleAsync = integral.CalculateAsync(); integral = Integral.Integral.GetIntegral(CalculationType.AverageRectangle, inputParameters); double resultAverageRectangle = integral.Calculate(); double resultAverageRectangleAsync = integral.CalculateAsync(); integral = Integral.Integral.GetIntegral(CalculationType.Trapezium, inputParameters); double resultTrapezium = integral.Calculate(); double resultTrapeziumAsync = integral.CalculateAsync(); integral = Integral.Integral.GetIntegral(CalculationType.Simpson, inputParameters); double resultSimpson = integral.Calculate(); double resultSimpsonAsync = integral.CalculateAsync(); Console.WriteLine($"Left rectangle: {resultLeftRectangle}"); Console.WriteLine($"Left rectangle async: {resultLeftRectangleAsync}"); Console.WriteLine($"Right rectangle: {resultRightRectangle}"); Console.WriteLine($"Right rectangle async: {resultRightRectangleAsync}"); Console.WriteLine($"Average rectangle: {resultAverageRectangle}"); Console.WriteLine($"Average rectangle async: {resultAverageRectangleAsync}"); Console.WriteLine($"Trapezium: {resultTrapezium}"); Console.WriteLine($"Trapezium async: {resultTrapeziumAsync}"); Console.WriteLine($"Simpson: {resultSimpson}"); Console.WriteLine($"Simpson async: {resultSimpsonAsync}"); Console.ReadKey(); }
public string Calculate(IntegralInput input) { StringBuilder stringBuilder = new StringBuilder(); foreach (CalculationType type in input.Types) { Integral.Integral integral = new Integral.Integral(input.Integrand, input.StartValue, input.EndValue, input.IterationsNumber, input.ParameterName); double result = integral.Calculate(type); stringBuilder.AppendLine($"{type.ToString()}: {result}"); } return(stringBuilder.ToString()); }
static void VerifyIntegrals() { string integrand = "x*x"; double startValue = -1; double endValue = 1; int iterationsNumber = 1000; string parameterName = "x"; Integral.Integral integral = new Integral.Integral(integrand, startValue, endValue, iterationsNumber, parameterName); double resultLeftRectangle = integral.Calculate(CalculationType.LeftRectangle); double resultRightRectangle = integral.Calculate(CalculationType.RightRectangle); double resultAverageRectangle = integral.Calculate(CalculationType.AverageRectangle); double resultTrapezium = integral.Calculate(CalculationType.Trapezium); double resultSimpson = integral.Calculate(CalculationType.Simpson); Console.WriteLine($"Left rectangle: {resultLeftRectangle}"); Console.WriteLine($"Right rectangle: {resultRightRectangle}"); Console.WriteLine($"Average rectangle: {resultAverageRectangle}"); Console.WriteLine($"Trapezium: {resultTrapezium}"); Console.WriteLine($"Simpson: {resultSimpson}"); Console.ReadKey(); }
/// <summary> /// Gets an appropriate Integral instance which implements a correct calculation method. /// </summary> /// <param name="calculationType">Calculation type.</param> /// <returns>An appropriate integral instance.</returns> public static Integral GetIntegral(CalculationType calculationType) { return(Integral.GetIntegral(calculationType, new IntegralInputParameters())); }