01 /*
02 * $Id: VdpolRk4StepLoop.java,v 1.4 2008/02/02 03:06:25 koga Exp $
03 *
04 * Copyright (C) 2004 Koga Laboratory. All rights reserved.
05 *
06 */
07 package matxbook.chap21;
08
09 import org.mklab.nfc.matrix.DoubleMatrix;
10 import org.mklab.nfc.matrix.Matrix;
11 import org.mklab.nfc.ode.DifferentialEquationSolver;
12 import org.mklab.nfc.ode.DifferentialEquation;
13 import org.mklab.nfc.ode.SolverStopException;
14 import org.mklab.nfc.ode.RungeKutta4;
15
16
17 /**
18 * @author koga
19 * @version $Revision: 1.4 $, 2004/04/22
20 */
21 public class VdpolRk4StepLoop {
22
23 /**
24 * メインメソッド
25 *
26 * @param args コマンドライン引数
27 * @throws SolverStopException ソルバーが停止された場合
28 */
29 public static void main(String[] args) throws SolverStopException {
30 DifferentialEquation eq = new Vdpol();
31 Matrix x0 = new DoubleMatrix(new double[] {0, 0.25}).transpose();
32 double t0 = 0.0;
33 double t1 = 20.0;
34 double timeStep = 0.1;
35 int n = (int)((t1 - t0) / timeStep);
36 DoubleMatrix tt = new DoubleMatrix(1, n + 1);
37 DoubleMatrix xx = new DoubleMatrix(2, n + 1);
38 DifferentialEquationSolver solver = new RungeKutta4();
39
40 Matrix x = x0;
41 double t = t0;
42 xx.setColumnVector(1, x);
43 tt.setElement(1, t);
44
45 for (int i = 1; i <= n; i++) {
46 x = solver.step(eq, t, x, timeStep);
47 t = t + timeStep;
48 xx.setColumnVector(i + 1, x);
49 tt.setElement(i + 1, t);
50 }
51 }
52 }
|