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 _10_UkladRownanRozniczkowych
{
  public partial class Form1 : Form
  {
    Log log;
    SystemDiffEqns diff = new SystemDiffEqns();

    public Form1()
    {
      InitializeComponent();
      log = new Log(textBox1);
      log.SetFontSize(20);
    }

    double fG(double x, double y, double u)
    {
      return u;
    }

    double fF(double x, double y, double u)
    {
      return Math.Sin(x) - y - u;
    }

    private void button1_Click(object sender, EventArgs e)
    {
      ChartForm.ClearAll();
      diff.a = 0;
      diff.b = 2;
      diff.n = 20;
      diff.g = fG;
      diff.f = fF;
      diff.x0 = 0;
      diff.y0 = 0;
      diff.u0 = 0;
      diff.RK4();
      double[][] w = new double[2][];
      w[0] = diff.X;
      w[1] = diff.Y;
      string[] hdr = new string[] { "X", "Y" };
      log.l(20, hdr, w);
      w[0] = diff.Y;
      w[1] = diff.U;
      hdr[0] = "Y";
      hdr[1] = "U";
      log.l(20, hdr, w);
      ChartForm.ShowLines(diff.X, diff.Y, "Y");
      ChartForm.ShowLines(diff.X, diff.U, "U");
    }

    double fg2(double x, double y, double u)
    {
      return u;
    }
    double ff2(double x, double y, double u)
    {
      return -(9.81 / 0.75) * Math.Sin(y);
    }

    private void button2_Click(object sender, EventArgs e)
    {
      ChartForm.ClearAll();
      diff.a = 0;
      diff.b = 10;
      diff.n = 1000;
      diff.x0 = 0;
      diff.y0 = 0.8;
      diff.u0 = 0;
      diff.g = fg2;
      diff.f = ff2;
      diff.RK4();
      ChartForm.ShowLines(diff.X, diff.Y, "Θ");
      ChartForm.ShowLines(diff.X, diff.U, "Θ'");
    }
  }
}
