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 * @author koga
23 * @version $Revision: 1.3 $, 2004/04/22
24 */
25 public class VdpolRk4Solution {
26
27 /**
28 * メインメソッド
29 *
30 * @param args コマンドライン引数
31 * @throws InterruptedException 強制終了された場合
32 * @throws IOException キーボードから入力できない場合
33 */
34 @SuppressWarnings("nls")
35 public static void main(String[] args) throws InterruptedException, IOException {
36 DifferentialEquation equation = new Vdpol();
37 Matrix x0 = new DoubleMatrix(new double[] {0, 0.25}).transpose();
38 DifferentialEquationSolver solver = new RungeKutta4();
39 solver.setTimeStep(0.1);
40 solver.solve(equation, 0.0, 20.0, x0);
41 DoubleMatrix tt = solver.getTimeSeries();
42 DoubleMatrix xx = solver.getDifferentialSolution();
43
44 Gnuplot gnuplot = new Gnuplot();
45 Canvas canvas = gnuplot.createCanvas();
46 canvas.setHolding(true);
47 canvas.plot(tt, xx, new String[] {"x1", "x2"});
48 canvas.plot((DoubleMatrix)xx.getRowVector(1), (DoubleMatrix)xx.getRowVector(2), new String[] {"x1-x2"});
49 canvas.setHolding(false);
50 Pause.pause();
51 gnuplot.close();
52 }
53 }
|