using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _07_1_Calkowanie
{
  public class Integrator
  {
    public double Prostokaty(double[] X, double[] Y)
    {
      double suma = 0;
      int n = X.Length - 1;
      double h = X[1] - X[0];
      for (int i = 0; i < n; i++)
        suma = suma + h * Y[i];
      return suma;
    }

    public double Trapezy(double[] X, double[] Y)
    {
      int n = X.Length - 1;
      double h = X[1] - X[0];
      double suma = (Y[0] + Y[n]) / 2;
      for (int i = 1; i < n; i++)
        suma = suma + Y[i];
      suma = suma * h;
      return suma;
    }

    public double Simpson(double[] X, double[] Y)
    {
      int n = X.Length - 1;
      double h = X[1] - X[0];
      double suma = Y[0] + Y[n];
      for (int i = 1; i < n; i++)
        if (i % 2 == 0)
          suma = suma + 2 * Y[i];
        else
          suma = suma + 4 * Y[i];

      suma = suma * h / 3;
      return suma;
    }

  }
}
