using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _10_UkladRownanRozniczkowych
{

  public delegate double F_xyu(double x, double y, double u);

  public class SystemDiffEqns
  {
    public F_xyu g;
    public F_xyu f;
    public double a;
    public double b;
    public double x0;
    public double y0;
    public double u0;
    //Ilość odcinków
    public int n;

    public double h;
    public double[] X;
    public double[] Y;
    public double[] U;

    public void RK4()
    {
      h = (b - a) / n;
      X = new double[n + 1];
      Y = new double[n + 1];
      U = new double[n + 1];
      X[0] = x0;
      Y[0] = y0;
      U[0] = u0;
      for (int i = 1; i <= n; i++)
      {
        double x = X[i - 1];
        double y = Y[i - 1];
        double u = U[i - 1];
        double k1 = h * g(x, y, u);
        double q1 = h * f(x, y, u);
        double k2 = h * g(x + h / 2, y + k1 / 2, u + q1 / 2);
        double q2 = h * f(x + h / 2, y + k1 / 2, u + q1 / 2);
        double k3 = h * g(x + h / 2, y + k2 / 2, u + q2 / 2);
        double q3 = h * f(x + h / 2, y + k2 / 2, u + q2 / 2);
        double k4 = h * g(x + h, y + k3, u + q3);
        double q4 = h * f(x + h, y + k3, u + q3);
        X[i] = x + h;
        Y[i] = y + (k1 + 2 * k2 + 2 * k3 + k4) / 6;
        U[i] = u + (q1 + 2 * q2 + 2 * q3 + q4) / 6;
      }


    }
  }
}
