Example: Runge-Kutta-Verner ordinary differential equation solver

An ordinary differential equation problem is solved using a solver which implements the Runge-Kutta-Verner method. The solution at time t=10 is printed.
import com.imsl.math.*;

public class OdeRungeKuttaEx1 {
    public static void main(String args[]) throws com.imsl.IMSLException {
        OdeRungeKutta.Function fcn = new OdeRungeKutta.Function() {
            public void f(double t, double y[], double yprime[]) {
                yprime[0] = 2. * y[0] * (1-y[1]);
                yprime[1] = -y[1] * (1-y[0]);
            }
        };
        
        double y[] = {1,3};
        OdeRungeKutta q = new OdeRungeKutta(fcn);
        int	nsteps = 10;
        for (int k = 0;  k < nsteps;  k++) {
            q.solve(k, k+1, y);
        }
        System.out.println("Result = {"+y[0]+","+y[1]+"}");
    }
}

Output

Result = {3.1443416765160768,0.3488265985196999}
Link to Java source.