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 _06_Newton_uklady_rownan
{
  public partial class Form1 : Form
  {

    Log log;

    public Form1()
    {
      InitializeComponent();
      log = new Log(textBox1);
      log.SetFontSize(18);
      log.SetFmtDigits(9);
    }

    double f1(double[] x) => x[0] * x[0] - 2 * x[1] * x[1];
    double f2(double[] x) => 2 * x[0] * x[1] - 3;
    double df1_dx1(double[] x) => 2 * x[0];
    double df1_dx2(double[] x) => -4 * x[1];
    double df2_dx1(double[] x) => 2 * x[1];
    double df2_dx2(double[] x) => 2 * x[0];

    private void button1_Click(object sender, EventArgs e)
    {
      Newton_Raphson nr = new Newton_Raphson();
      double eps = double.Parse(tbEps.Text);
      double[] x0 = new double[] { 1.3, 1.1 };
      FW[] funs = new FW[] { f1, f2 };
      FW[,] fprims = new FW[,] { { df1_dx1, df1_dx2 }, { df2_dx1, df2_dx2 } };
      double[] x = nr.Oblicz(eps, x0, funs, fprims);
      log.l($"Rozwiązanie układu równań nieliniowych (iteracji {nr.licznik}):", x);
    }
  }
}
