using GenDanDoZad;
using System;
using System.Windows.Forms;

namespace _07_2_Calkowanie
{
    public partial class Form1 : Form
  {
    Log log;
    Preprocesor prep = new Preprocesor();
    Integrator integr = new Integrator();

    double ex2(double x)
    {
      return Math.Exp(-x * x / 2);
    }

    public Form1()
    {
      InitializeComponent();
      log = new Log(tbLog);
      log.SetFontSize(16);
    }

    private void button1_Click(object sender, EventArgs e)
    {
      prep.a = 0;
      prep.b = 2;
      prep.n = 10;
      prep.fun = ex2;
      prep.Oblicz();
      double calka = integr.Prostokaty(prep.X, prep.Y);
      log.l("X:",prep.X,true);
      log.l("Y:", prep.Y, true);
      log.l($"całka Prost.: {calka}");
    }

    private void button2_Click(object sender, EventArgs e)
    {
      prep.a = 0;
      prep.b = 2;
      prep.n = 10;
      prep.fun = ex2;
      prep.Oblicz();
      double calka = integr.Trapezy(prep.X, prep.Y);
      log.l("X:", prep.X, true);
      log.l("Y:", prep.Y, true);
      log.l($"całka Trap.: {calka}");
    }

    private void button3_Click(object sender, EventArgs e)
    {
      prep.a = 0;
      prep.b = 2;
      prep.n = 10;
      prep.fun = ex2;
      prep.Oblicz();
      double calka = integr.Simpson(prep.X, prep.Y);
      log.l("X:", prep.X, true);
      log.l("Y:", prep.Y, true);
      log.l($"całka Simp.: {calka}");
    }

    double wp = 1.19628801332261;
    double eps = 0.0001;

    private void button4_Click(object sender, EventArgs e)
    {
      double calka;
      int N = 4;
      do {
        prep.a = 0;
        prep.b = 2;
        prep.n = N;
        prep.fun = ex2;
        prep.Oblicz();
        calka = integr.Prostokaty(prep.X, prep.Y);
        N = N + 2;
      } while (Math.Abs(calka-wp) > eps);
      log.l($"Met.prost. calka: {calka} liczba N: {prep.n}");
    }

    private void button5_Click(object sender, EventArgs e)
    {
      double calka;
      int N = 4;
      do
      {
        prep.a = 0;
        prep.b = 2;
        prep.n = N;
        prep.fun = ex2;
        prep.Oblicz();
        calka = integr.Trapezy(prep.X, prep.Y);
        N = N + 2;
      } while (Math.Abs(calka - wp) > eps);
      log.l($"Met.trap. calka: {calka} liczba N: {prep.n}");
    }

    private void button6_Click(object sender, EventArgs e)
    {
      double calka;
      int N = 4;
      do
      {
        prep.a = 0;
        prep.b = 2;
        prep.n = N;
        prep.fun = ex2;
        prep.Oblicz();
        calka = integr.Simpson(prep.X, prep.Y);
        N = N + 2;
      } while (Math.Abs(calka - wp) > eps);
      log.l($"Met.Simp. calka: {calka} liczba N: {prep.n}");
    }



    //Funkcja: f(x) = (x+1)^0.5
    double Pierw1PlusX(double x)
    {
      return Math.Sqrt(1 + x);
    }
    //Całka (bez stałej całkowania) z (x+1)^0.5 
    double CPierw1PlusX(double x)
    {
      return 2 * Math.Pow(x + 1, 1.5) / 3;
    }


  }
}
