01 /*
02 * $Id: Motor2ObserverSampledDataRKFSimulationAuto.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.DifferentialEquationAutoSolver;
14 import org.mklab.nfc.ode.RungeKuttaFehlberg;
15 import org.mklab.nfc.util.Pause;
16 import org.mklab.tool.control.system.SystemSolver;
17 import org.mklab.tool.graph.gnuplot.Canvas;
18 import org.mklab.tool.graph.gnuplot.Gnuplot;
19
20
21 /**
22 * モータと離散時間オブザーバの結合システムのシミュレーション計算をRKF法(誤差指定)で行うサンプルです。
23 * @author koga
24 * @version $Revision: 1.3 $, 2004/04/23
25 */
26 public class Motor2ObserverSampledDataRKFSimulationAuto {
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 Motor2DiscreteObserver system = new Motor2DiscreteObserver();
38 Matrix xc0 = new DoubleMatrix(new double[] {1, 0}).transpose();
39 Matrix xd0 = new DoubleMatrix(new double[] {0}).transpose();
40 system.setContinuousInitialState(xc0);
41 system.setDiscreteInitialState(xd0);
42 system.setSamplingInterval(0.5);
43
44 DifferentialEquationAutoSolver solver = new RungeKuttaFehlberg();
45 solver.setTolerance(1.0E-05);
46 solver.setSaveAtSamplingPoint(true);
47 long startTime = System.nanoTime();
48 new SystemSolver(solver).solveAuto(system, 0, 10);
49 System.out.println("Simulation time = " + (System.nanoTime() - startTime) * 1e-9);
50 DoubleMatrix tt = solver.getTimeSeries();
51 DoubleMatrix xc = solver.getContinuousStateSeries();
52 DoubleMatrix xd = solver.getDiscreteStateSeries();
53 DoubleMatrix io = solver.getInputOutputSeries();
54
55 Gnuplot gnuplot = new Gnuplot();
56 Canvas canvas = gnuplot.createCanvas();
57 canvas.setHolding(true);
58 canvas.plot(tt, xc, new String[] {"x1", "x2"});
59 canvas.plot(tt, xd, new String[] {"xd"});
60 canvas.plot(tt, io, new String[] {"u", "y"});
61 canvas.setHolding(false);
62 Pause.pause();
63 gnuplot.close();
64 }
65 }
|