01 /*
02 * $Id: VdpolRk4Solution.java,v 1.3 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 java.io.IOException;
10
11 import org.mklab.nfc.matrix.DoubleMatrix;
12 import org.mklab.nfc.matrix.Matrix;
13 import org.mklab.nfc.ode.DifferentialEquationSolver;
14 import org.mklab.nfc.ode.DifferentialEquation;
15 import org.mklab.nfc.ode.RungeKutta4;
16 import org.mklab.nfc.util.Pause;
17 import org.mklab.tool.graph.gnuplot.Canvas;
18 import org.mklab.tool.graph.gnuplot.Gnuplot;
19
20
21 /**
22 * ヴァンデルポール方程式を4次のルンゲ・クッタ法で解くクラスです。
23 * @author koga
24 * @version $Revision: 1.3 $, 2004/04/22
25 */
26 public class VdpolRk4Solution {
27
28 /**
29 * メインメソッド
30 *
31 * @param args コマンドライン引数
32 * @throws InterruptedException 強制終了された場合
33 * @throws IOException キーボードから入力できない場合
34 */
35 @SuppressWarnings("nls")
36 public static void main(String[] args) throws InterruptedException, IOException {
37 DifferentialEquation equation = new Vdpol();
38 Matrix x0 = new DoubleMatrix(new double[] {0, 0.25}).transpose();
39 DifferentialEquationSolver solver = new RungeKutta4();
40 solver.setTimeStep(0.1);
41 solver.solve(equation, 0.0, 20.0, x0);
42 DoubleMatrix tt = solver.getTimeSeries();
43 DoubleMatrix xx = solver.getDifferentialSolution();
44
45 Gnuplot gnuplot = new Gnuplot();
46 Canvas canvas = gnuplot.createCanvas();
47 canvas.setHolding(true);
48 canvas.plot(tt, xx, new String[] {"x1", "x2"});
49 canvas.plot(xx.getRowVector(1), xx.getRowVector(2), new String[] {"x1-x2"});
50 canvas.setHolding(false);
51 Pause.pause();
52 gnuplot.close();
53 }
54 }
|