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_2_Newton_ulady_rownan
{
  public partial class Form1 : Form
  {
    Log log;
    public Form1()
    {
      InitializeComponent();
      log = new Log(tbLog);
      log.SetFontSize(16);
      log.SetFmtDigits(10);
    }

    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_x1(double[] x) => 2 * x[0];
    double df1_x2(double[] x) => -4 * x[1];
    double df2_x1(double[] x) => 2 * x[1];
    double df2_x2(double[] x) => 2 * x[0];

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