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