Package cnuphys.rk4
Class RungeKutta
java.lang.Object
cnuphys.rk4.RungeKutta
Static methods for Runge-Kutta 4 integration, including a constant stepsize
 method and an adaptive stepsize method.
- Author:
- heddle
- 
Field SummaryFields
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionintadaptiveStep(double[] yo, double[] yf, double to, double tf, double h, double maxH, IDerivative deriv, IStopper stopper, ButcherTableau tableau, double[] relTolerance, double[] hdata) Integrator that uses the RungeKutta advance with a Butcher Tableau and adaptive stepsize This version uses an IRk4Listener to notify the listener that the next step has been advanced.intadaptiveStep(double[] yo, double to, double tf, double h, IDerivative deriv, IStopper stopper, IRkListener listener, ButcherTableau tableau, double[] relTolerance, double[] hdata) Integrator that uses the RungeKutta advance with a Butcher Tableau and adaptive stepsize This version uses an IRk4Listener to notify the listener that the next step has been advanced.intadaptiveStep(double[] yo, double to, double tf, double h, IDerivative deriv, IStopper stopper, IRkListener listener, ButcherTableau tableau, double eps, double[] yscale, double[] hdata) Integrator that uses the RungeKutta advance with a Butcher Tableau and adaptive stepsize.intadaptiveStep(double[] yo, double to, double tf, double h, List<Double> t, List<double[]> y, IDerivative deriv, IStopper stopper, ButcherTableau tableau, double[] relTolerance, double[] hdata) Integrator that uses the RungeKutta advance with a Butcher Tableau and adaptive stepsize and a tolerance vector.intadaptiveStep(double[] yo, double to, double tf, double h, List<Double> t, List<double[]> y, IDerivative deriv, IStopper stopper, ButcherTableau tableau, double eps, double[] yscale, double[] hdata) Integrator that uses the RungeKutta advance with a Butcher Tableau and adaptive stepsize.doubleGet the maximum step sizedoubleGet the minimum step sizevoidsetMaxStepSize(double maxSS) Set the maximum step sizevoidsetMinStepSize(double minSS) Set the minimum step sizeintuniformStep(double[] yo, double to, double tf, double[][] y, double[] t, IDerivative deriv, IStopper stopper) Driver that uses the RungeKutta advance with a uniform step size.intuniformStep(double[] yo, double to, double tf, double h, IDerivative deriv, IStopper stopper, IRkListener listener) Integrator that uses the standard RK4 advance with a uniform step size.intuniformStep(double[] yo, double to, double tf, double h, IDerivative deriv, IStopper stopper, IRkListener listener, ButcherTableau tableau) Integrator that uses the RungeKutta advance with a Butcher Tableau and constant stepsize.
- 
Field Details- 
DEFMINSTEPSIZEpublic static double DEFMINSTEPSIZE
- 
DEFMAXSTEPSIZEpublic static double DEFMAXSTEPSIZE
 
- 
- 
Constructor Details- 
RungeKuttapublic RungeKutta()Create a RungeKutta object that can be used for integration
 
- 
- 
Method Details- 
uniformSteppublic int uniformStep(double[] yo, double to, double tf, double[][] y, double[] t, IDerivative deriv, IStopper stopper) Driver that uses the RungeKutta advance with a uniform step size. (i.e., this does NOT use an adaptive step size.) This version stores each step into the arrays t[] and y[][]. An alternative does not store the results but instead uses an IRk4Listener to notify the listener that the next step has been advanced. A very typical case is a 2nd order ODE converted to a 1st order where the dependent variables are x, y, z, vx, vy, vz and the independent variable is time.- Parameters:
- yo- initial values. Probably something like (xo, yo, zo, vxo, vyo, vzo).
- to- the initial value of the independent variable, e.g., time.
- tf- the maximum value of the independent variable.
- y- will be filled with results. The first index is small-- the dimensionality of the problem-- i.e., often it is 6 for (xo, yo, zo, vxo, vyo, vzo). The second dimension is for storing results and determining stepsize. If it is 1000, we will have a thousand steps and the stepsize will be (tf-to)/1000 (actually 999).
- t- will filled with the locations of t--should have the exact same large dimension as the second index of y--i.e., something like 1000.
- deriv- the derivative computer (interface). This is where the problem specificity resides.
- stopper- if not- nullwill be used to exit the integration early because some condition has been reached.
- Returns:
- the number of steps used--may be less than the space provided if the integration ended early as a result of an exit condition.
 
- 
uniformSteppublic int uniformStep(double[] yo, double to, double tf, double h, IDerivative deriv, IStopper stopper, IRkListener listener) Integrator that uses the standard RK4 advance with a uniform step size. (i.e., this does NOT use an adaptive step size.) This version uses an IRk4Listener to notify the listener that the next step has been advanced. A very typical case is a 2nd order ODE converted to a 1st order where the dependent variables are x, y, z, vx, vy, vz and the independent variable is time.- Parameters:
- yo- initial values. Probably something like (xo, yo, zo, vxo, vyo, vzo).
- to- the initial value of the independent variable, e.g., time.
- tf- the maximum value of the independent variable.
- deriv- the derivative computer (interface). This is where the problem specificity resides.
- stopper- if not- nullwill be used to exit the integration early because some condition has been reached.
- listener- listens for each step
- Returns:
- the number of steps used.
 
- 
uniformSteppublic int uniformStep(double[] yo, double to, double tf, double h, IDerivative deriv, IStopper stopper, IRkListener listener, ButcherTableau tableau) Integrator that uses the RungeKutta advance with a Butcher Tableau and constant stepsize. (i.e., this does NOT use an adaptive step size.) This version uses an IRk4Listener to notify the listener that the next step has been advanced. A very typical case is a 2nd order ODE converted to a 1st order where the dependent variables are x, y, z, vx, vy, vz and the independent variable is time.- Parameters:
- yo- initial values. Probably something like (xo, yo, zo, vxo, vyo, vzo).
- to- the initial value of the independent variable, e.g., time.
- tf- the maximum value of the independent variable.
- deriv- the derivative computer (interface). This is where the problem specificity resides.
- stopper- if not- nullwill be used to exit the integration early because some condition has been reached.
- listener- listens for each step
- tableau- the Butcher Tableau
- Returns:
- the number of steps used.
 
- 
adaptiveSteppublic int adaptiveStep(double[] yo, double to, double tf, double h, List<Double> t, List<double[]> y, IDerivative deriv, IStopper stopper, ButcherTableau tableau, double[] relTolerance, double[] hdata) throws RungeKuttaException Integrator that uses the RungeKutta advance with a Butcher Tableau and adaptive stepsize and a tolerance vector. This version uses an IRk4Listener to notify the listener that the next step has been advanced. A very typical case is a 2nd order ODE converted to a 1st order where the dependent variables are x, y, z, vx, vy, vz and the independent variable is time.- Parameters:
- yo- initial values. Probably something like (xo, yo, zo, vxo, vyo, vzo).
- to- the initial value of the independent variable, e.g., time.
- tf- the maximum value of the independent variable.
- h- the starting steps size
- t- a list of the values of t at each step
- y- a list of the values of the state vector at each step
- deriv- the derivative computer (interface). This is where the problem specificity resides.
- stopper- if not- nullwill be used to exit the integration early because some condition has been reached.
- tableau- the Butcher Tableau
- relTolerance- the error tolerance as fractional diffs. Note it is a vector, the same dimension of the problem, e.g., 6 for [x,y,z,vx,vy,vz].
- hdata- if not null, should be double[3]. Upon return, hdata[0] is the min stepsize used, hdata[1] is the average stepsize used, and hdata[2] is the max stepsize used
- Returns:
- the number of steps used.
- Throws:
- RungeKuttaException
 
- 
adaptiveSteppublic int adaptiveStep(double[] yo, double to, double tf, double h, IDerivative deriv, IStopper stopper, IRkListener listener, ButcherTableau tableau, double[] relTolerance, double[] hdata) throws RungeKuttaException Integrator that uses the RungeKutta advance with a Butcher Tableau and adaptive stepsize This version uses an IRk4Listener to notify the listener that the next step has been advanced. A very typical case is a 2nd order ODE converted to a 1st order where the dependent variables are x, y, z, vx, vy, vz and the independent variable is time.- Parameters:
- yo- initial values. Probably something like (xo, yo, zo, vxo, vyo, vzo).
- to- the initial value of the independent variable, e.g., time.
- tf- the maximum value of the independent variable.
- h- the starting steps size
- deriv- the derivative computer (interface). This is where the problem specificity resides.
- stopper- if not- nullwill be used to exit the integration early because some condition has been reached.
- listener- listens for each step
- tableau- the Butcher Tableau
- relTolerance- the error tolerance as fractional diffs. Note it is a vector, the same
- hdata- if not null, should be double[3]. Upon return, hdata[0] is the min stepsize used, hdata[1] is the average stepsize used, and hdata[2] is the max stepsize used
- Returns:
- the number of steps used.
- Throws:
- RungeKuttaException
 
- 
adaptiveSteppublic int adaptiveStep(double[] yo, double[] yf, double to, double tf, double h, double maxH, IDerivative deriv, IStopper stopper, ButcherTableau tableau, double[] relTolerance, double[] hdata) throws RungeKuttaException Integrator that uses the RungeKutta advance with a Butcher Tableau and adaptive stepsize This version uses an IRk4Listener to notify the listener that the next step has been advanced. A very typical case is a 2nd order ODE converted to a 1st order where the dependent variables are x, y, z, vx, vy, vz and the independent variable is time.- Parameters:
- yo- initial values. Probably something like (xo, yo, zo, vxo, vyo, vzo).
- yf- space for final state vector
- to- the initial value of the independent variable, e.g., time.
- tf- the maximum value of the independent variable.
- h- the starting steps size
- deriv- the derivative computer (interface). This is where the problem specificity resides.
- stopper- if not- nullwill be used to exit the integration early because some condition has been reached.
- tableau- the Butcher Tableau
- relTolerance- the error tolerance as fractional diffs. Note it is a vector, the same
- hdata- if not null, should be double[3]. Upon return, hdata[0] is the min stepsize used, hdata[1] is the average stepsize used, and hdata[2] is the max stepsize used
- Returns:
- the number of steps used.
- Throws:
- RungeKuttaException
 
- 
adaptiveSteppublic int adaptiveStep(double[] yo, double to, double tf, double h, List<Double> t, List<double[]> y, IDerivative deriv, IStopper stopper, ButcherTableau tableau, double eps, double[] yscale, double[] hdata) throws RungeKuttaException Integrator that uses the RungeKutta advance with a Butcher Tableau and adaptive stepsize. This uses an desired absolute error relative to some scale (of max values of the dependent variables) This version uses an IRk4Listener to notify the listener that the next step has been advanced. A very typical case is a 2nd order ODE converted to a 1st order where the dependent variables are x, y, z, vx, vy, vz and the independent variable is time.- Parameters:
- yo- initial values. Probably something like (xo, yo, zo, vxo, vyo, vzo).
- to- the initial value of the independent variable, e.g., time.
- tf- the maximum value of the independent variable.
- h- the starting steps size
- t- a list of the values of t at each step
- y- a list of the values of the state vector at each step
- deriv- the derivative computer (interface). This is where the problem specificity resides.
- stopper- if not- nullwill be used to exit the integration early because some condition has been reached.
- tableau- the Butcher Tableau
- eps- the required accuracy
- yscale- scale the error against this array. It can be the approximate max value of each component of y, which gives you constant absolute errors, or it can be null in which case y will be used and you have constant relative error.
- hdata- if not null, should be double[3]. Upon return, hdata[0] is the min stepsize used, hdata[1] is the average stepsize used, and hdata[2] is the max stepsize used
- Returns:
- the number of steps used.
- Throws:
- RungeKuttaException
 
- 
adaptiveSteppublic int adaptiveStep(double[] yo, double to, double tf, double h, IDerivative deriv, IStopper stopper, IRkListener listener, ButcherTableau tableau, double eps, double[] yscale, double[] hdata) throws RungeKuttaException Integrator that uses the RungeKutta advance with a Butcher Tableau and adaptive stepsize. This uses an desired absolute error relative to some scale (of max values of the dependent variables) This version uses an IRk4Listener to notify the listener that the next step has been advanced. A very typical case is a 2nd order ODE converted to a 1st order where the dependent variables are x, y, z, vx, vy, vz and the independent variable is time.- Parameters:
- yo- initial values. Probably something like (xo, yo, zo, vxo, vyo, vzo).
- to- the initial value of the independent variable, e.g., time.
- tf- the maximum value of the independent variable.
- h- the starting steps size
- deriv- the derivative computer (interface). This is where the problem specificity resides.
- stopper- if not- nullwill be used to exit the integration early because some condition has been reached.
- listener- listens for each step
- tableau- the Butcher Tableau
- eps- the required accuracy
- yscale- scale the error against this array. It can be the approximate max value of each component of y, which gives you constant absolute errors, or it can be null in which case y will be used and you have constant relative error.
- hdata- if not null, should be double[3]. Upon return, hdata[0] is the min stepsize used, hdata[1] is the average stepsize used, and hdata[2] is the max stepsize used
- Returns:
- the number of steps used.
- Throws:
- RungeKuttaException
 
- 
setMaxStepSizepublic void setMaxStepSize(double maxSS) Set the maximum step size- Parameters:
- maxSS- the maximum stepsize is whatever units you are using
 
- 
setMinStepSizepublic void setMinStepSize(double minSS) Set the minimum step size- Parameters:
- maxSS- the minimum stepsize is whatever units you are using
 
- 
getMaxStepSizepublic double getMaxStepSize()Get the maximum step size- Returns:
- the maximum stepsize is whatever units you are using
 
- 
getMinStepSizepublic double getMinStepSize()Get the minimum step size- Returns:
- the minimum stepsize is whatever units you are using
 
 
-