package com.imsl.test.example.math; import com.imsl.math.*; /** *
* Solves an ODE using the Runge-Kutta-Verner method.
* * 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. * * * @see Code * @see Output * */ 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] + "}"); } }