Motor2ObserverSampledDataRKFSimulation.java
01 /*
02  * $Id: Motor2ObserverSampledDataRKFSimulation.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.RungeKuttaFehlberg;
15 import org.mklab.nfc.ode.SolverStopException;
16 import org.mklab.nfc.util.Pause;
17 import org.mklab.tool.control.system.SystemSolver;
18 import org.mklab.tool.graph.gnuplot.Canvas;
19 import org.mklab.tool.graph.gnuplot.Gnuplot;
20 
21 
22 /**
23  * モータと離散時間オブザーバの結合システムのシミュレーション計算をRKF法(5次のルンゲ・クッタ)で行うサンプルです。
24  @author koga
25  @version $Revision: 1.3 $, 2004/04/23
26  */
27 public class Motor2ObserverSampledDataRKFSimulation {
28 
29   /**
30    * メインメソッド
31    
32    @param args コマンドライン引数
33    @throws InterruptedException 強制終了された場合
34    @throws IOException キーボードから入力できない場合
35    @throws SolverStopException ソルバーが停止された場合
36    */
37   @SuppressWarnings("nls")
38   public static void main(String[] argsthrows InterruptedException, IOException, SolverStopException {
39     Motor2DiscreteObserver system = new Motor2DiscreteObserver();
40     Matrix xc0 = new DoubleMatrix(new double[] {10}).transpose();
41     Matrix xd0 = new DoubleMatrix(new double[] {0}).transpose();
42     system.setContinuousInitialState(xc0);
43     system.setDiscreteInitialState(xd0);
44     system.setSamplingInterval(0.5);
45 
46     DifferentialEquationSolver solver = new RungeKuttaFehlberg();
47     solver.setTimeStep(0.1);
48     solver.setSaveAtSamplingPoint(true);
49     new SystemSolver(solver).solve(system, 010);
50     DoubleMatrix tt = solver.getTimeSeries();
51     DoubleMatrix xc = solver.getContinuousStateSeries();
52     DoubleMatrix xd = solver.getDiscreteStateSeries();
53     // Matrix uy = ans[3];
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, uy, new String[] {"u", "y"});
61     canvas.setHolding(false);
62     Pause.pause();
63     gnuplot.close();
64   }
65 }