using GenDanDoZad;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace _09_Rozniczkowanie
{
  public partial class Form1 : Form
  {
    Log log;

    public Form1()
    {
      InitializeComponent();
      log = new Log(textBox1);
      textBox1.Font = new Font("Consolas", 18);
    }


    double Wiel(double x)
    {
      return -0.1 * x * x * x * x - 0.15 * x * x * x
        - 0.5 * x * x - 0.25 * x + 1.2;
    }
    double PWiel(double x)
    {
      return -0.4 * x * x * x - 0.45 * x * x - x - 0.25;
    }

    double err(double wa, double wr)
    {
      return 100 * Math.Abs((wa - wr) / wr);
    }

    Differentator dif = new Differentator();


    public void Rozniczkuj(double h)
    {
      double x = 0.5;
      dif.h = h;
      dif.f = Wiel;
      double wA = PWiel(x);
      double wR = dif.Regr(x);
      double wP = dif.Prog(x);
      double wC = dif.Cent(x);
      double wT = dif.Prec(x);
      log.l($"Pochodne funkcji Wiel(x) w punkcie x={x} (Real <=> analitycznie) h={dif.h}");
      log.l($"Real: {wA,20}");
      log.l($"Regr: {wR,20}    err:{err(wR, wA)} %");
      log.l($"Prog: {wP,20}    err:{err(wP, wA)} %");
      log.l($"Cent: {wC,20}    err:{err(wC, wA)} %");
      log.l($"Prec: {wT,20}    err:{err(wT, wA)} %");
    }


    private void button1_Click(object sender, EventArgs e)
    {
      Rozniczkuj(0.5);
    }

    private void button2_Click(object sender, EventArgs e)
    {
      Rozniczkuj(0.25);
    }

    private void button3_Click(object sender, EventArgs e)
    {
      Rozniczkuj(0.125);
    }

    private void button4_Click(object sender, EventArgs e)
    {
      Rozniczkuj(0.0625);
    }
  }
}
