Class NumericalIntegration

java.lang.Object
edu.wpi.first.math.system.NumericalIntegration

public final class NumericalIntegration
extends Object
  • Method Details

    • rk4

      public static double rk4​(DoubleFunction<Double> f, double x, double dtSeconds)
      Performs Runge Kutta integration (4th order).
      Parameters:
      f - The function to integrate, which takes one argument x.
      x - The initial value of x.
      dtSeconds - The time over which to integrate.
      Returns:
      the integration of dx/dt = f(x) for dt.
    • rk4

      public static double rk4​(BiFunction<Double,​Double,​Double> f, double x, Double u, double dtSeconds)
      Performs Runge Kutta integration (4th order).
      Parameters:
      f - The function to integrate. It must take two arguments x and u.
      x - The initial value of x.
      u - The value u held constant over the integration period.
      dtSeconds - The time over which to integrate.
      Returns:
      The result of Runge Kutta integration (4th order).
    • rk4

      public static <States extends Num,​ Inputs extends Num> Matrix<States,​N1> rk4​(BiFunction<Matrix<States,​N1>,​Matrix<Inputs,​N1>,​Matrix<States,​N1>> f, Matrix<States,​N1> x, Matrix<Inputs,​N1> u, double dtSeconds)
      Performs 4th order Runge-Kutta integration of dx/dt = f(x, u) for dt.
      Type Parameters:
      States - A Num representing the states of the system to integrate.
      Inputs - A Num representing the inputs of the system to integrate.
      Parameters:
      f - The function to integrate. It must take two arguments x and u.
      x - The initial value of x.
      u - The value u held constant over the integration period.
      dtSeconds - The time over which to integrate.
      Returns:
      the integration of dx/dt = f(x, u) for dt.
    • rk4

      public static <States extends Num> Matrix<States,​N1> rk4​(Function<Matrix<States,​N1>,​Matrix<States,​N1>> f, Matrix<States,​N1> x, double dtSeconds)
      Performs 4th order Runge-Kutta integration of dx/dt = f(x) for dt.
      Type Parameters:
      States - A Num prepresenting the states of the system.
      Parameters:
      f - The function to integrate. It must take one argument x.
      x - The initial value of x.
      dtSeconds - The time over which to integrate.
      Returns:
      4th order Runge-Kutta integration of dx/dt = f(x) for dt.
    • rkf45

      public static <States extends Num,​ Inputs extends Num> Matrix<States,​N1> rkf45​(BiFunction<Matrix<States,​N1>,​Matrix<Inputs,​N1>,​Matrix<States,​N1>> f, Matrix<States,​N1> x, Matrix<Inputs,​N1> u, double dtSeconds)
      Performs adaptive RKF45 integration of dx/dt = f(x, u) for dt, as described in https://en.wikipedia.org/wiki/Runge%E2%80%93Kutta%E2%80%93Fehlberg_method. By default, the max error is 1e-6.
      Type Parameters:
      States - A Num representing the states of the system to integrate.
      Inputs - A Num representing the inputs of the system to integrate.
      Parameters:
      f - The function to integrate. It must take two arguments x and u.
      x - The initial value of x.
      u - The value u held constant over the integration period.
      dtSeconds - The time over which to integrate.
      Returns:
      the integration of dx/dt = f(x, u) for dt.
    • rkf45

      public static <States extends Num,​ Inputs extends Num> Matrix<States,​N1> rkf45​(BiFunction<Matrix<States,​N1>,​Matrix<Inputs,​N1>,​Matrix<States,​N1>> f, Matrix<States,​N1> x, Matrix<Inputs,​N1> u, double dtSeconds, double maxError)
      Performs adaptive RKF45 integration of dx/dt = f(x, u) for dt, as described in https://en.wikipedia.org/wiki/Runge%E2%80%93Kutta%E2%80%93Fehlberg_method
      Type Parameters:
      States - A Num representing the states of the system to integrate.
      Inputs - A Num representing the inputs of the system to integrate.
      Parameters:
      f - The function to integrate. It must take two arguments x and u.
      x - The initial value of x.
      u - The value u held constant over the integration period.
      dtSeconds - The time over which to integrate.
      maxError - The maximum acceptable truncation error. Usually a small number like 1e-6.
      Returns:
      the integration of dx/dt = f(x, u) for dt.
    • rkdp

      public static <States extends Num,​ Inputs extends Num> Matrix<States,​N1> rkdp​(BiFunction<Matrix<States,​N1>,​Matrix<Inputs,​N1>,​Matrix<States,​N1>> f, Matrix<States,​N1> x, Matrix<Inputs,​N1> u, double dtSeconds)
      Performs adaptive Dormand-Prince integration of dx/dt = f(x, u) for dt. By default, the max error is 1e-6.
      Type Parameters:
      States - A Num representing the states of the system to integrate.
      Inputs - A Num representing the inputs of the system to integrate.
      Parameters:
      f - The function to integrate. It must take two arguments x and u.
      x - The initial value of x.
      u - The value u held constant over the integration period.
      dtSeconds - The time over which to integrate.
      Returns:
      the integration of dx/dt = f(x, u) for dt.
    • rkdp

      public static <States extends Num,​ Inputs extends Num> Matrix<States,​N1> rkdp​(BiFunction<Matrix<States,​N1>,​Matrix<Inputs,​N1>,​Matrix<States,​N1>> f, Matrix<States,​N1> x, Matrix<Inputs,​N1> u, double dtSeconds, double maxError)
      Performs adaptive Dormand-Prince integration of dx/dt = f(x, u) for dt.
      Type Parameters:
      States - A Num representing the states of the system to integrate.
      Inputs - A Num representing the inputs of the system to integrate.
      Parameters:
      f - The function to integrate. It must take two arguments x and u.
      x - The initial value of x.
      u - The value u held constant over the integration period.
      dtSeconds - The time over which to integrate.
      maxError - The maximum acceptable truncation error. Usually a small number like 1e-6.
      Returns:
      the integration of dx/dt = f(x, u) for dt.