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 * @author koga
23 * @version $Revision: 1.3 $, 2004/04/23
24 */
25 public class Motor2ObserverSampledDataRKFSimulationAuto {
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 Motor2DiscreteObserver system = new Motor2DiscreteObserver();
37 Matrix xc0 = new DoubleMatrix(new double[] {1, 0}).transpose();
38 Matrix xd0 = new DoubleMatrix(new double[] {0}).transpose();
39 system.setContinuousInitialState(xc0);
40 system.setDiscreteInitialState(xd0);
41 system.setSamplingInterval(0.5);
42
43 DifferentialEquationAutoSolver solver = new RungeKuttaFehlberg();
44 solver.setTolerance(1.0E-05);
45 solver.setSaveAtSamplingPoint(true);
46 long startTime = System.nanoTime();
47 new SystemSolver(solver).solveAuto(system, 0, 10);
48 System.out.println("Simulation time = " + (System.nanoTime() - startTime) * 1e-9);
49 DoubleMatrix tt = solver.getTimeSeries();
50 DoubleMatrix xc = solver.getContinuousStateSeries();
51 DoubleMatrix xd = solver.getDiscreteStateSeries();
52 DoubleMatrix io = solver.getInputOutputSeries();
53
54 Gnuplot gnuplot = new Gnuplot();
55 Canvas canvas = gnuplot.createCanvas();
56 canvas.setHolding(true);
57 canvas.plot(tt, xc, new String[] {"x1", "x2"});
58 canvas.plot(tt, xd, new String[] {"xd"});
59 canvas.plot(tt, io, new String[] {"u", "y"});
60 canvas.setHolding(false);
61 Pause.pause();
62 gnuplot.close();
63 }
64 }
|