01 /*
02 * $Id: Motor2ObserverRK4Simulation2.java,v 1.4 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.RungeKutta4;
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 * @author koga
24 * @version $Revision: 1.4 $, 2004/04/23
25 */
26 public class Motor2ObserverRK4Simulation2 {
27
28 /**
29 * メインメソッド
30 *
31 * @param args コマンドライン引数
32 * @throws InterruptedException 強制終了された場合
33 * @throws IOException キーボードから入力できない場合
34 * @throws SolverStopException ソルバーが停止された場合
35 */
36 @SuppressWarnings("nls")
37 public static void main(String[] args) throws InterruptedException, IOException, SolverStopException {
38 Motor2ContinuousObserver2 system = new Motor2ContinuousObserver2();
39 Matrix x0 = new DoubleMatrix(new double[] {0, 0}).transpose();
40 Matrix z0 = new DoubleMatrix(new double[] {1});
41 Matrix initialState = x0.appendDown(z0);
42 system.setInitialState(initialState);
43
44 DifferentialEquationSolver solver = new RungeKutta4();
45 solver.setTimeStep(0.1);
46 new SystemSolver(solver).solve(system, 0, 10);
47 DoubleMatrix tt = solver.getTimeSeries();
48 DoubleMatrix xx = solver.getContinuousStateSeries();
49 DoubleMatrix io = solver.getInputOutputSeries();
50
51 Gnuplot gnuplot = new Gnuplot();
52 Canvas canvas = gnuplot.createCanvas();
53 canvas.setHolding(true);
54 canvas.plot(tt, (DoubleMatrix)xx.getRowVectors(1, 2), new String[] {"x1", "x2"});
55 canvas.plot(tt, (DoubleMatrix)io.getRowVectors(3, 4), new String[] {"xh1", "xh2"});
56 canvas.setHolding(false);
57 Pause.pause();
58 gnuplot.close();
59 }
60 }
|