Demo.java
/*
* $Id: Demo.java,v 1.46 2008/07/17 13:35:52 koga Exp $
*
* Copyright (C) 2004 Koga Laboratory. All rights reserved.
*/
package org.mklab.tool.control;
import java.io.IOException;
import java.util.List;
import org.mklab.nfc.matrix.DoubleComplexMatrix;
import org.mklab.nfc.matrix.DoubleMatrix;
import org.mklab.nfc.scalar.DoubleComplexNumber;
import org.mklab.nfc.scalar.DoubleNumber;
import org.mklab.nfc.scalar.DoublePolynomial;
import org.mklab.nfc.scalar.DoubleRationalPolynomial;
import org.mklab.nfc.util.Pause;
import org.mklab.tool.Menu;
import org.mklab.tool.graph.gnuplot.Canvas;
import org.mklab.tool.graph.gnuplot.Gnuplot;
import org.mklab.tool.matrix.Linspace;
import org.mklab.tool.matrix.Logspace;
import org.mklab.tool.matrix.Makepoly;
/**
* 制御系設計ツールボックスのデモンストレーションを行うクラスです。
*
* @author koga
* @version $Revision: 1.46 $
*/
public class Demo {
/**
* メインメソッド
*
* @param args コマンドライン引数
*/
public static void main(String[] args) {
new Demo().run();
}
/**
* デモンストレーションを実行します。
*/
public void run() {
String title = Messages.getString("Demo.0"); //$NON-NLS-1$
String options[] = new String[] {
Messages.getString("Demo.1"), Messages.getString("Demo.2"), Messages.getString("Demo.3"), Messages.getString("Demo.4"), Messages.getString("Demo.5"), Messages.getString("Demo.6")}; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$
int i = 1;
for (;;) {
try {
i = Menu.menu(title, options, i);
switch (i) {
case 1:
runTransferFunctionExample();
break;
case 2:
runPoleAssignExample();
break;
case 3:
runServoProblemExample();
break;
case 4:
runObserverExample();
break;
case 5:
runLqrExample();
break;
default:
throw new IllegalArgumentException();
}
} catch (IOException e) {
throw new RuntimeException(e);
}
if (i == 0 || i == options.length) {
break;
}
}
}
/**
* システムの伝達関数と周波数応答を求めます。
*
* @throws IOException キーボードから入力できない場合
*/
private void runTransferFunctionExample() throws IOException {
System.out.println(""); //$NON-NLS-1$
System.out.println(Messages.getString("Demo.8")); //$NON-NLS-1$
System.out.println(" 2 "); //$NON-NLS-1$
System.out.println(" 0.2 s + 0.3 s + 1 "); //$NON-NLS-1$
System.out.println("H(s) = -------------------------------"); //$NON-NLS-1$
System.out.println(" 2 "); //$NON-NLS-1$
System.out.println(" (s + 0.4 s + 1) (s + 0.5)"); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
System.out.println(Messages.getString("Demo.15")); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
System.out.println("\tPolynomial s = new DoublePolynomial(\"s\");"); //$NON-NLS-1$
System.out.println("\tPolynomial numP = s.power(2).multiply(0.2).add(s.multiply(0.3)).add(1);"); //$NON-NLS-1$
System.out.println("\tPolynomial denP = s.power(2).add(s.multiply(0.4)).add(1).multiply(s.add(0.5));"); //$NON-NLS-1$
System.out.println("\tRationalPolynomial g = numP.divide(denP);"); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
Pause.pause();
DoublePolynomial s = new DoublePolynomial("s"); //$NON-NLS-1$
DoublePolynomial numP = s.power(2).multiply(0.2).add(s.multiply(0.3)).add(1);
DoublePolynomial denP = s.power(2).add(s.multiply(0.4)).add(1).multiply(s.add(0.5));
DoubleRationalPolynomial g = new DoubleRationalPolynomial(numP, denP);
System.out.println(Messages.getString("Demo.23")); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
System.out.println("\tList<DoubleMatrix> numDen = Tfn2tf.tfn2tf(g);"); //$NON-NLS-1$
System.out.println("\tMatrix num = numDen.get(0);"); //$NON-NLS-1$
System.out.println("\tMatrix den = numDen.get(1);"); //$NON-NLS-1$
System.out.println("\tnum.print(\"num\");"); //$NON-NLS-1$
System.out.println("\tden.print(\"den\");"); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
Pause.pause();
final List<DoubleMatrix> numDen = Tfn2tf.tfn2tf(g);
final DoubleMatrix num = numDen.get(0);
final DoubleMatrix den = numDen.get(1);
num.print("num"); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
den.print("den"); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
System.out.println(Messages.getString("Demo.35")); //$NON-NLS-1$
System.out.println("\t. "); //$NON-NLS-1$
System.out.println("\tx = Ax + Bu "); //$NON-NLS-1$
System.out.println("\ty = Cx + Du "); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
System.out.println("List<DoubleMatrix> abcd = Tf2ss.tf2ss(num, den);"); //$NON-NLS-1$
System.out.println("\tMatrix A = abcd.get(0);"); //$NON-NLS-1$
System.out.println("\tMatrix B = abcd.get(1);"); //$NON-NLS-1$
System.out.println("\tMatrix C = abcd.get(2);"); //$NON-NLS-1$
System.out.println("\tMatrix D = abcd.get(3);"); //$NON-NLS-1$
System.out.println("\tA.print(\"A\");"); //$NON-NLS-1$
System.out.println("\tB.print(\"B\");"); //$NON-NLS-1$
System.out.println("\tC.print(\"C\");"); //$NON-NLS-1$
System.out.println("\tD.print(\"D\");"); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
Pause.pause();
final List<DoubleMatrix> abcd = Tf2ss.tf2ss(num, den);
final DoubleMatrix A = abcd.get(0);
final DoubleMatrix B = abcd.get(1);
final DoubleMatrix C = abcd.get(2);
final DoubleMatrix D = abcd.get(3);
A.print("A"); //$NON-NLS-1$
B.print("B"); //$NON-NLS-1$
C.print("C"); //$NON-NLS-1$
D.print("D"); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
System.out.println(Messages.getString("Demo.55")); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
System.out.println("\tList<DoubleMatrix> zpk = Ss2zp.ss2zp(A, B, C, D);"); //$NON-NLS-1$
System.out.println("\tMatrix ze = zpk.get(0);"); //$NON-NLS-1$
System.out.println("\tMatrix po = zpk.get(1);"); //$NON-NLS-1$
System.out.println("\tMatrix kk = zpk.get(2);"); //$NON-NLS-1$
System.out.println("\tpo.print(\"po\");"); //$NON-NLS-1$
System.out.println("\tze.print(\"ze\");"); //$NON-NLS-1$
System.out.println("\tkk.print(\"kk\");"); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
Pause.pause();
List<DoubleComplexMatrix> zpk = Ss2zp.ss2zp(A, B, C, D);
DoubleComplexMatrix ze = zpk.get(0);
DoubleComplexMatrix po = zpk.get(1);
DoubleMatrix kk = zpk.get(2).getRealPart();
po.print("po"); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
ze.print("ze"); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
kk.print("kk"); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
System.out.println(Messages.getString("Demo.71")); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
System.out.println("\tg = Ss2tfn.ss2tfn(A, B, C, D);"); //$NON-NLS-1$
System.out.println("\tg.print(\"g\");"); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
Pause.pause();
g = Ss2tfn.ss2tfn(A, B, C, D);
g.print("g"); //$NON-NLS-1$
Gnuplot gp = null;
// 根軌跡
System.out.println(""); //$NON-NLS-1$
System.out.println(Messages.getString("Demo.78")); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
System.out.println("\tMatrix k = DoubleMatrix.series(0, 10, 0.5);"); //$NON-NLS-1$
System.out.println("\tgp = new Gnuplot();"); //$NON-NLS-1$
System.out.println("\tgp.reset();"); //$NON-NLS-1$
System.out.println("\tRlocus.plot(gp, num, den, k);"); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
Pause.pause();
DoubleMatrix k = DoubleMatrix.series(0, 10, 0.5);
gp = new Gnuplot();
gp.reset();
Rlocus.plot(gp, num, den, k);
// ステップ応答
System.out.println(Messages.getString("Demo.83")); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
System.out.println("\tMatrix t = DoubleMatrix.series(0, 15, 0.3);"); //$NON-NLS-1$
System.out.println("\tStep.plot(A, B, C, D, 1, t);"); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
Pause.pause();
DoubleMatrix t = DoubleMatrix.series(0, 15, 0.3);
gp.reset();
Step.plot(gp, A, B, C, D, 1, t);
// ボード線図
System.out.println(Messages.getString("Demo.88")); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
System.out.println("\tMatrix w = Logspace.logspace(0.001, 1000.0, 1000);"); //$NON-NLS-1$
System.out.println("\tgp.reset();"); //$NON-NLS-1$
System.out.println("\tnew Bode(new LinearSystem(g)).plot(gp, w);"); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
Pause.pause();
DoubleMatrix w = Logspace.logspace(0.001, 1000.0, 1000);
gp.reset();
new DoubleBode(DoubleLinearSystemFactory.createLinearSystem(g)).plot(gp, w);
// ナイキスト線図
System.out.println(Messages.getString("Demo.93")); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
System.out.println("\tgp.reset();"); //$NON-NLS-1$
System.out.println("\tnew Nyquist(new LinearSystem(g)).plot(gp, w);"); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
Pause.pause();
gp.reset();
new DoubleNyquist(DoubleLinearSystemFactory.createLinearSystem(g)).plot(gp, w);
Pause.pause();
gp.close();
}
/**
* 極配置問題を解く。
*
* @throws IOException キーボードから入力できない場合
*/
private void runPoleAssignExample() throws IOException {
System.out.println(""); //$NON-NLS-1$
System.out.println(Messages.getString("Demo.98")); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
System.out.println("\tMatrix A = new DoubleMatrix(new double[][]{{0,1,0},{0,0,1},{-6,-11,-6}});"); //$NON-NLS-1$
System.out.println("\tMatrix B = new DoubleMatrix(new double[][]{{0},{0},{10}});"); //$NON-NLS-1$
// System.out.println("\tMatrix C = new DoubleMatrix(new double[]{1,0,0});");
// System.out.println("\tMatrix D = new DoubleMatrix(new double[]{0});");
System.out.println(""); //$NON-NLS-1$
Pause.pause();
DoubleMatrix A = new DoubleMatrix(new double[][] { {0, 1, 0}, {0, 0, 1}, {-6, -11, -6}});
DoubleMatrix B = new DoubleMatrix(new double[][] { {0}, {0}, {10}});
// DoubleMatrix C = new DoubleMatrix(new double[]{1,0,0});
// DoubleMatrix D = new DoubleMatrix(new double[]{0});
System.out.println(Messages.getString("Demo.103")); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
System.out.println("\tMatrix V = Ctrm.ctrm(A,B);"); //$NON-NLS-1$
System.out.println("\tV.print(\"V\");"); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
Pause.pause();
DoubleMatrix V = Ctrm.ctrm(A, B);
V.print("V"); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
System.out.println(Messages.getString("Demo.110")); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
System.out.println("\tSystem.out.println(((NumericalMatrix)V).rank());"); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
Pause.pause();
System.out.println(V.rank());
System.out.println(""); //$NON-NLS-1$
System.out.println(Messages.getString("Demo.115")); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
System.out.println("\tPolynomial p = Makepoly.makepoly(A);"); //$NON-NLS-1$
System.out.println("\tp.print(\"p\");"); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
Pause.pause();
DoublePolynomial p = Makepoly.makepoly(A);
p.print("p"); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
System.out.println(Messages.getString("Demo.122")); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
System.out.println("\tMatrix N = new DoubleMatrix(new double[][]{{p.getRealCoefficient(1),p.getRealCoefficient(2),1},"); //$NON-NLS-1$
System.out.println("\t p.getRealCoefficient(2),1,0},{1,0,0}});"); //$NON-NLS-1$
System.out.println("\tMatrix T = V.multiply(N);"); //$NON-NLS-1$
System.out.println("\tT.print(\"T\");"); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
Pause.pause();
DoubleMatrix N = new DoubleMatrix(new double[][] { {p.getCoefficient(1).doubleValue(), p.getCoefficient(2).doubleValue(), 1},
{p.getCoefficient(2).doubleValue(), 1, 0}, {1, 0, 0}});
DoubleMatrix T = V.multiply(N);
T.print("T"); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
System.out.println(Messages.getString("Demo.131")); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
System.out.println("\tComplexMatrix cc = new DoubleComplexMatrix(new newDoubleComplexNumber[]"); //$NON-NLS-1$
System.out.println("\t {new DoubleComplexNumber(-2,3), new DoubleComplexNumber(-2,-3), new DoubleComplexNumber(-10,0)});"); //$NON-NLS-1$
System.out.println("\tPolynomial pc = Makepoly.makepoly(cc).getRealPart();"); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
Pause.pause();
DoubleComplexMatrix cc = new DoubleComplexMatrix(new DoubleComplexNumber[] {new DoubleComplexNumber(-2, 3), new DoubleComplexNumber(-2, -3), new DoubleComplexNumber(-10, 0)});
DoublePolynomial pc = Makepoly.makepoly(cc);
System.out.println(""); //$NON-NLS-1$
System.out.println(Messages.getString("Demo.138")); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
System.out.println("\tMatrix ppc = new DoubleMatrix(new DoubleNumber[]{pc.getCoefficient(0)-p.getRealCoefficient(0),"); //$NON-NLS-1$
System.out.println("\t pc.getRealCoefficient(1)-p.getRealCoefficient(1),"); //$NON-NLS-1$
System.out.println("\t pc.getRealCoefficient(2)-p.getRealCoefficient(2)});"); //$NON-NLS-1$
System.out.println("\tMatrix F = ppc.multiply(T.inverse());"); //$NON-NLS-1$
System.out.println("\tF.print(\"F\");"); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
Pause.pause();
DoubleMatrix ppc = new DoubleMatrix(new DoubleNumber[] {pc.getCoefficient(0).subtract(p.getCoefficient(0)), pc.getCoefficient(1).subtract(p.getCoefficient(1)),
pc.getCoefficient(2).subtract(p.getCoefficient(2))});
DoubleMatrix F = ppc.multiply(T.inverse());
F.print("F"); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
System.out.println(Messages.getString("Demo.148")); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
System.out.println("\t((NumericalMatrixOperator<?>)A.subtract(B.multiply(F))).eigenValue().print(\"eigval(A - B*F)\");"); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
Pause.pause();
A.subtract(B.multiply(F)).eigenValue().print("eigval(A - B*F)"); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
Pause.pause();
}
/**
* 1形サーボ系を設計します。
*
* @throws IOException キーボードから入力できない場合
*/
private void runServoProblemExample() throws IOException {
System.out.println(""); //$NON-NLS-1$
System.out.println(Messages.getString("Demo.155")); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
System.out.println("\tMatrix A = new DoubleMatrix(new double[][]{{0,1,0,0},"); //$NON-NLS-1$
System.out.println("\t {20,0,0,0},"); //$NON-NLS-1$
System.out.println("\t {0,0,0,1},"); //$NON-NLS-1$
System.out.println("\t {-0.5,0,0,0}});"); //$NON-NLS-1$
System.out.println("\tMatrix B = new DoubleMatrix(new double[][]{{0},{-1},{0},{0.5}});"); //$NON-NLS-1$
System.out.println("\tMatrix C = new DoubleMatrix(new double[]{0,0,1,0});"); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
Pause.pause();
DoubleMatrix A = new DoubleMatrix(new double[][] { {0, 1, 0, 0}, {20, 0, 0, 0}, {0, 0, 0, 1}, {-0.5, 0, 0, 0}});
DoubleMatrix B = new DoubleMatrix(new double[][] { {0}, {-1}, {0}, {0.5}});
DoubleMatrix C = new DoubleMatrix(new double[] {0, 0, 1, 0});
// DoubleMatrix D = new DoubleMatrix(new double[]{0});
System.out.println(Messages.getString("Demo.164")); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
System.out.println("\tMatrix Aa = A.appendRight(new DoubleMatrix(4,1)).appendDown("); //$NON-NLS-1$
System.out.println("\t C.unaryMinus().appendRight(DoubleMatrix.Z(1)));"); //$NON-NLS-1$
System.out.println("\tMatrix Ba = B.appendDown(DoubleMatrix.Z(1));"); //$NON-NLS-1$
System.out.println("\tAa.print(\"Aa\");"); //$NON-NLS-1$
System.out.println("\tBa.print(\"Ba\");"); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
Pause.pause();
DoubleMatrix Aa = A.appendRight(new DoubleMatrix(4, 1)).appendDown(C.unaryMinus().appendRight(new DoubleMatrix(1, 1)));
DoubleMatrix Ba = B.appendDown(new DoubleMatrix(1, 1));
Aa.print("Aa"); //$NON-NLS-1$
Ba.print("Ba"); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
System.out.println(Messages.getString("Demo.175")); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
System.out.println("\tMatrix V = Ctrm.ctrm(Aa, Ba);"); //$NON-NLS-1$
System.out.println("\tV.print(\"V\");"); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
Pause.pause();
DoubleMatrix V = Ctrm.ctrm(Aa, Ba);
V.print("V"); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
System.out.println(Messages.getString("Demo.182")); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
System.out.println("\tSystem.out.println(((NumericalMatrix)V).rank());"); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
Pause.pause();
System.out.println(V.rank());
System.out.println(""); //$NON-NLS-1$
System.out.println(Messages.getString("Demo.187")); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
System.out.println("\tMatrix P = new ComplexMatrix(new Complex[][]{"); //$NON-NLS-1$
System.out.println("\t {new Complex(-1,Math.sqrt(3))},"); //$NON-NLS-1$
System.out.println("\t {new Complex(-1,-Math.sqrt(3))},"); //$NON-NLS-1$
System.out.println("\t {new Complex(-5,0)},"); //$NON-NLS-1$
System.out.println("\t {new Complex(-5,0)},"); //$NON-NLS-1$
System.out.println("\t {new Complex(-5,0)}});"); //$NON-NLS-1$
System.out.println("\tP.print(\"P\");"); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
Pause.pause();
DoubleComplexMatrix P = new DoubleComplexMatrix(new DoubleComplexNumber[][] { {new DoubleComplexNumber(-1, Math.sqrt(3))}, {new DoubleComplexNumber(-1, -Math.sqrt(3))}, {new DoubleComplexNumber(-5, 0)},
{new DoubleComplexNumber(-5, 0)}, {new DoubleComplexNumber(-5, 0)}});
P.print("P"); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
System.out.println(Messages.getString("Demo.199")); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
System.out.println("\tMatrix Fa = Pplace.pplace(Aa, Ba, P);"); //$NON-NLS-1$
System.out.println("\tFa.print(\"Fa\");"); //$NON-NLS-1$
System.out.println("\tdouble Fi = - Fa.getRealElement(5);"); //$NON-NLS-1$
System.out.println("\tSystem.out.println(\"Fi = \" + Fi);"); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
Pause.pause();
DoubleMatrix Fa = Pplace.pplace(Aa, Ba, P);
Fa.print("Fa"); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
double Fi = -Fa.getDoubleElement(5);
System.out.println("Fi = " + Fi); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
Pause.pause();
System.out.println(Messages.getString("Demo.210")); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
System.out.println("\tMatrix F = Fa.getSubVector(1,4);"); //$NON-NLS-1$
System.out.println("\tF.print(\"F\");"); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
Pause.pause();
DoubleMatrix F = Fa.getSubVector(1, 4);
F.print("F"); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
System.out.println(Messages.getString("Demo.217")); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
System.out.println("\tMatrix Ac = A.subtract(B.multiply(F)).appendRight(B.multiply(Fi))."); //$NON-NLS-1$
System.out.println("\t appendDown(C.unaryMinus().appendRight(DoubleMatrix.Z(1)));"); //$NON-NLS-1$
System.out.println("\tMatrix Bc = new DoubleMatrix(new double [][]{{0},{0},{0},{0},{1}});"); //$NON-NLS-1$
System.out.println("\tMatrix Cc = C.appendRight(DoubleMatrix.Z(1));"); //$NON-NLS-1$
System.out.println("\tMatrix Dc = DoubleMatrix.Z(1);"); //$NON-NLS-1$
System.out.println("\tAc.print(\"Ac\");"); //$NON-NLS-1$
System.out.println("\tB.print(\"Bc\");"); //$NON-NLS-1$
System.out.println("\tCc.print(\"Cc\");"); //$NON-NLS-1$
System.out.println("\tDc.print(\"Dc\");"); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
Pause.pause();
DoubleMatrix Ac = A.subtract(B.multiply(F)).appendRight(B.multiply(Fi)).appendDown(C.unaryMinus().appendRight(new DoubleMatrix(1, 1)));
DoubleMatrix Bc = new DoubleMatrix(new double[][] { {0}, {0}, {0}, {0}, {1}});
DoubleMatrix Cc = C.appendRight(new DoubleMatrix(1, 1));
DoubleMatrix Dc = new DoubleMatrix(1, 1);
Ac.print("Ac"); //$NON-NLS-1$
B.print("Bc"); //$NON-NLS-1$
Cc.print("Cc"); //$NON-NLS-1$
Dc.print("Dc"); //$NON-NLS-1$
System.out.println(Messages.getString("Demo.233")); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
System.out.println("\tMatrix T = Linspace.linspace(0.0, 5.0);"); //$NON-NLS-1$
System.out.println("\tList<DoubleMatrix> tmp = Step.step(Ac, Bc, Cc, Dc, 1, T);"); //$NON-NLS-1$
System.out.println("\tMatrix Y = tmp.get(0);"); //$NON-NLS-1$
System.out.println("\tMatrix X = tmp.get(1);"); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
Pause.pause();
DoubleMatrix T = Linspace.linspace(0.0, 5.0);
List<DoubleMatrix> yx = Step.step(Ac, Bc, Cc, Dc, 1, T);
DoubleMatrix Y = yx.get(0);
DoubleMatrix X = yx.get(1);
System.out.println(Messages.getString("Demo.240")); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
System.out.println("\tGnuplot gp = new Gnuplot();"); //$NON-NLS-1$
System.out.println("\tgp.subplot(2, 1, 1);"); //$NON-NLS-1$
System.out.println("\tgp.grid(true);"); //$NON-NLS-1$
System.out.println("\tgp.title(\"Output y versus Time t\");"); //$NON-NLS-1$
System.out.println("\tgp.xlabel(\"Sec\");"); //$NON-NLS-1$
System.out.println("\tgp.ylabel(\"Output y = x3\");"); //$NON-NLS-1$
System.out.println("\tgp.plot(T, Y, new String[]{\"y\"});"); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
Pause.pause();
Gnuplot gp = null;
gp = new Gnuplot();
gp.createCanvas(2, 1);
Canvas canvas1 = gp.getCanvas(0, 0);
canvas1.setGridVisible(true);
canvas1.setTitle("Output y versus Time t"); //$NON-NLS-1$
canvas1.setXLabel("Sec"); //$NON-NLS-1$
canvas1.setYLabel("Output y = x3"); //$NON-NLS-1$
canvas1.plot(T, Y, new String[] {"y"}); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
System.out.println(Messages.getString("Demo.255")); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
System.out.println("\tgp.subplot(2, 1, 2);"); //$NON-NLS-1$
System.out.println("\tgp.grid(true);"); //$NON-NLS-1$
System.out.println("\tgp.title(\"Response Curves for x1, x2, x3, x4, x5\");"); //$NON-NLS-1$
System.out.println("\tgp.xlabel(\"Sec\");"); //$NON-NLS-1$
System.out.println("\tgp.ylabel(\"x1, x2, x3, x4, x5\");"); //$NON-NLS-1$
System.out.println("\tgp.text(\"x1\", 1.2, 0.05);"); //$NON-NLS-1$
System.out.println("\tgp.text(\"x2\", 1.2, -0.32);"); //$NON-NLS-1$
System.out.println("\tgp.text(\"x3\", 1.2, 0.33);"); //$NON-NLS-1$
System.out.println("\tgp.text(\"x4\", 2.2, 0.25);"); //$NON-NLS-1$
System.out.println("\tgp.text(\"x5\", 1.5, 1.28);"); //$NON-NLS-1$
System.out.println("\tgp.plot(T, X, new String[]{\"x1\", \"x2\", \"x3\", \"x4\", \"x5\"});"); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
Pause.pause();
Canvas canvas2 = gp.getCanvas(1, 0);
canvas2.setGridVisible(true);
canvas2.setTitle("Response Curves for x1, x2, x3, x4, x5"); //$NON-NLS-1$
canvas2.setXLabel("Sec"); //$NON-NLS-1$
canvas2.setYLabel("x1, x2, x3, x4, x5"); //$NON-NLS-1$
canvas2.setText("x1", 1.2, 0.05); //$NON-NLS-1$
canvas2.setText("x2", 1.2, -0.32); //$NON-NLS-1$
canvas2.setText("x3", 1.2, 0.33); //$NON-NLS-1$
canvas2.setText("x4", 2.2, 0.25); //$NON-NLS-1$
canvas2.setText("x5", 1.5, 1.28); //$NON-NLS-1$
canvas2.plot(T, X, new String[] {"x1", "x2", "x3", "x4", "x5"}); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
Pause.pause();
gp.close();
}
/**
* 全状態オブザーバを設計します。
*
* @throws IOException キーボードから入力できない場合
*/
private void runObserverExample() throws IOException {
System.out.println(""); //$NON-NLS-1$
System.out.println(Messages.getString("Demo.283")); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
System.out.println("\tMatrix A = new DoubleMatrix(new double[][]{{0,1,0},{0,0,1},{-5,-10,-5}});"); //$NON-NLS-1$
System.out.println("\tMatrix C = new DoubleMatrix(new double[]{1,0,0});"); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
Pause.pause();
DoubleMatrix A = new DoubleMatrix(new double[][] { {0, 1, 0}, {0, 0, 1}, {-5, -10, -5}});
DoubleMatrix C = new DoubleMatrix(new double[] {1, 0, 0});
System.out.println(Messages.getString("Demo.288")); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
System.out.println("\tMatrix N = Obsm.obsm(A,C);"); //$NON-NLS-1$
System.out.println("\tN.print(\"N\");"); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
Pause.pause();
DoubleMatrix N = Obsm.obsm(A, C);
N.print("N"); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
System.out.println(Messages.getString("Demo.295")); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
System.out.println("\tSystem.out.println(((NumericalMatrix)N).rank());"); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
Pause.pause();
System.out.println(N.rank());
System.out.println(""); //$NON-NLS-1$
System.out.println(Messages.getString("Demo.300")); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
System.out.println("\tPolynomial p = Makepoly.makepoly(A);"); //$NON-NLS-1$
System.out.println("\tp.print(\"p\");"); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
Pause.pause();
DoublePolynomial p = Makepoly.makepoly(A);
p.print("p"); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
System.out.println(Messages.getString("Demo.307")); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
System.out.println("\tMatrix W = new DoubleMatrix(new double[][]{"); //$NON-NLS-1$
System.out.println("\t {p.getRealCoefficient(1),p.getRealCoefficient(2),1},"); //$NON-NLS-1$
System.out.println("\t {p.getRealCoefficient(2),1,0},{1,0,0}});"); //$NON-NLS-1$
System.out.println("\tMatrix T = W.multiply(N.transpose());"); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
Pause.pause();
DoubleMatrix W = new DoubleMatrix(new double[][] { {p.getCoefficient(1).doubleValue(), p.getCoefficient(2).doubleValue(), 1},
{p.getCoefficient(2).doubleValue(), 1, 0}, {1, 0, 0}});
DoubleMatrix T = W.multiply(N.transpose());
System.out.println(""); //$NON-NLS-1$
System.out.println(Messages.getString("Demo.315")); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
System.out.println("\tMatrix poc = new ComplexMatrix(new Complex[]{new Complex(-2,1),"); //$NON-NLS-1$
System.out.println("\t new Complex(-2,-1),"); //$NON-NLS-1$
System.out.println("\t new Complex(-5,0)});"); //$NON-NLS-1$
System.out.println("\tPolynomial po = Makepoly.makepoly(poc).getRealPart();"); //$NON-NLS-1$
System.out.println("\tpo.print(\"po\");"); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
Pause.pause();
DoubleComplexMatrix poc = new DoubleComplexMatrix(new DoubleComplexNumber[] {new DoubleComplexNumber(-2, 1), new DoubleComplexNumber(-2, -1), new DoubleComplexNumber(-5, 0)});
DoublePolynomial po = Makepoly.makepoly(poc);
po.print("po"); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
System.out.println(Messages.getString("Demo.325")); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
System.out.println("\tMatrix Fom = new DoubleMatrix(new double[]{po.getRealCoefficient(0)-p.getRealCoefficient(0),"); //$NON-NLS-1$
System.out.println("\t po.getRealCoefficient(1)-p.getRealCoefficient(1),"); //$NON-NLS-1$
System.out.println("\t po.getRealCoefficient(2)-p.getRealCoefficient(2)});"); //$NON-NLS-1$
System.out.println("\tMatrix Fo = T.leftDivide(Fom.transpose());"); //$NON-NLS-1$
System.out.println("\tFo.print(\"Fo\");"); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
Pause.pause();
DoubleMatrix Fom = new DoubleMatrix(new DoubleNumber[] {po.getCoefficient(0).subtract(p.getCoefficient(0)), po.getCoefficient(1).subtract(p.getCoefficient(1)),
po.getCoefficient(2).subtract(p.getCoefficient(2))});
DoubleMatrix Fo = T.leftDivide(Fom.transpose());
Fo.print("Fo"); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
Pause.pause();
}
/**
* 線形二次形式最適レギュレータを設計します。
*
* @throws IOException キーボードから入力できない場合
*/
private void runLqrExample() throws IOException {
System.out.println(""); //$NON-NLS-1$
System.out.println(Messages.getString("Demo.336")); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
System.out.println("\tMatrix A = new DoubleMatrix(new double[][]{{0,1,0},{0,0,1},{-35,-27,-9}});"); //$NON-NLS-1$
System.out.println("\tMatrix B = new DoubleMatrix(new double[][]{{0},{0},{1}});"); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
Pause.pause();
DoubleMatrix A = new DoubleMatrix(new double[][] { {0, 1, 0}, {0, 0, 1}, {-35, -27, -9}});
DoubleMatrix B = new DoubleMatrix(new double[][] { {0}, {0}, {1}});
System.out.println(Messages.getString("Demo.341")); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
System.out.println("\tMatrix Q = DoubleMatrix.I(3).multiply(100);"); //$NON-NLS-1$
System.out.println("\tMatrix R = DoubleMatrix.I(1);"); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
Pause.pause();
DoubleMatrix Q = DoubleMatrix.unit(3).multiply(100);
DoubleMatrix R = DoubleMatrix.unit(1);
System.out.println(Messages.getString("Demo.346")); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
System.out.println("\tList<DoubleMatrix> fp = Lqr.lqr(A,B,Q,R);"); //$NON-NLS-1$
System.out.println("\tMatrix F = fp.get(0);"); //$NON-NLS-1$
System.out.println("\tF.print(\"F\");"); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
Pause.pause();
final List<DoubleMatrix> fp = Lqr.lqr(A, B, Q, R);
final DoubleMatrix F = fp.get(0);
F.print("F"); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
System.out.println(Messages.getString("Demo.354")); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
System.out.println("\tMatrix pc = ((NumericalMatrix)A.subtract(B.multiply(F))).eigenValue();"); //$NON-NLS-1$
System.out.println("\tpc.print(\"pc\");"); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
Pause.pause();
DoubleComplexMatrix pc = A.subtract(B.multiply(F)).eigenValue();
pc.print("pc"); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
System.out.println(Messages.getString("Demo.361")); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
System.out.println("\tMatrix C = DoubleMatrix.unit(3);"); //$NON-NLS-1$
System.out.println("\tMatrix D = new DoubleMatrix(3,1);"); //$NON-NLS-1$
System.out.println("\tMatrix to = Linspace.linspace(0.0, 5.0);"); //$NON-NLS-1$
System.out.println("\tList<DoubleMatrix> yxo = Step.step(A, B, C, D, 1, to);"); //$NON-NLS-1$
System.out.println("\tMatrix yo = yxo.get(0);"); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
Pause.pause();
final DoubleMatrix C = DoubleMatrix.unit(3);
final DoubleMatrix D = new DoubleMatrix(3, 1);
final DoubleMatrix to = Linspace.linspace(0.0, 5.0);
final List<DoubleMatrix> yxo = Step.step(A, B, C, D, 1, to);
final DoubleMatrix yo = yxo.get(0);
// DoubleMatrix xo = tmp.getMatrix(2);
System.out.println(Messages.getString("Demo.369")); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
System.out.println("\tGnuplot gp = new Gnuplot();"); //$NON-NLS-1$
System.out.println("\tgp.subplot(3, 1, 1);"); //$NON-NLS-1$
System.out.println("\tgp.grid(true);"); //$NON-NLS-1$
System.out.println("\tgp.title(\"Output yo1\");"); //$NON-NLS-1$
System.out.println("\tgp.plot(to, yo.getRowVector(1), new String[]{\"yo1\"});"); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
Pause.pause();
Gnuplot gp = null;
gp = new Gnuplot();
gp.createCanvas(3, 1);
Canvas canvas1 = gp.getCanvas(0, 0);
canvas1.setGridVisible(true);
canvas1.setTitle("Output yo1"); //$NON-NLS-1$
canvas1.plot(to, yo.getRowVector(1), new String[] {"yo1"}); //$NON-NLS-1$
System.out.println(Messages.getString("Demo.379")); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
System.out.println("\tgp.subplot(3, 1, 2);"); //$NON-NLS-1$
System.out.println("\tgp.grid(true);"); //$NON-NLS-1$
System.out.println("\tgp.title(\"Output yo2\");"); //$NON-NLS-1$
System.out.println("\tgp.plot(to, yo.getRowVector(2), new String[]{\"yo2\"});"); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
Pause.pause();
Canvas canvas2 = gp.getCanvas(1, 0);
canvas2.setGridVisible(true);
canvas2.setTitle("Output yo2"); //$NON-NLS-1$
canvas2.plot(to, yo.getRowVector(2), new String[] {"yo2"}); //$NON-NLS-1$
System.out.println(Messages.getString("Demo.7")); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
System.out.println("\tgp.subplot(3, 1, 3);"); //$NON-NLS-1$
System.out.println("\tgp.grid(true);"); //$NON-NLS-1$
System.out.println("\tgp.title(\"Output yo3\");"); //$NON-NLS-1$
System.out.println("\tgp.plot(to, yo.getRowVector(3), new String[]{\"yo3\"});"); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
Pause.pause();
Canvas canvas3 = gp.getCanvas(2, 0);
canvas3.setGridVisible(true);
canvas3.setTitle("Output yo3"); //$NON-NLS-1$
canvas3.plot(to, yo.getRowVector(3), new String[] {"yo3"}); //$NON-NLS-1$
System.out.println(Messages.getString("Demo.397")); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
System.out.println("\tMatrix Ac = A.subtract(B.multiply(F));"); //$NON-NLS-1$
System.out.println("\tMatrix Cc = C.subtract(D.multiply(F));"); //$NON-NLS-1$
System.out.println("\tMatrix tc = Linspace.linspace(0.0, 5.0);"); //$NON-NLS-1$
System.out.println("\tList<DoubleMatrix> yxc = Step.step(Ac, B, Cc, D, 1, tc);"); //$NON-NLS-1$
System.out.println("\tMatrix yc = yxc.get(0);"); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
Pause.pause();
DoubleMatrix Ac = A.subtract(B.multiply(F));
DoubleMatrix Cc = C.subtract(D.multiply(F));
DoubleMatrix tc = Linspace.linspace(0.0, 5.0);
List<DoubleMatrix> yxc = Step.step(Ac, B, Cc, D, 1, tc);
DoubleMatrix yc = yxc.get(0);
// DoubleMatrix xc = tmp.getMatrix(2);
System.out.println(Messages.getString("Demo.405")); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
System.out.println("\tgp.subplot(3, 1, 1);"); //$NON-NLS-1$
System.out.println("\tgp.grid(true);"); //$NON-NLS-1$
System.out.println("\tgp.title(\"Output yo1 and yc1\");"); //$NON-NLS-1$
System.out.println("\tgp.replot(tc, yc.getRowVector(1), new String[]{\"yc1\"});"); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
Pause.pause();
canvas1.setGridVisible(true);
canvas1.setTitle("Output yo1 and yc1"); //$NON-NLS-1$
canvas1.setHolding(true);
canvas1.plot(tc, yc.getRowVector(1), new String[] {"yc1"}); //$NON-NLS-1$
canvas1.setHolding(false);
System.out.println(Messages.getString("Demo.414")); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
System.out.println("\tgp.subplot(3, 1, 2);"); //$NON-NLS-1$
System.out.println("\tgp.grid(true);"); //$NON-NLS-1$
System.out.println("\tgp.title(\"Output yo2 and yc2\");"); //$NON-NLS-1$
System.out.println("\tgp.replot(tc, yc.getRowVector(2), new String[]{\"yc2\"});"); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
Pause.pause();
canvas2.setGridVisible(true);
canvas2.setTitle("Output yo2 and yc2"); //$NON-NLS-1$
canvas2.setHolding(true);
canvas2.plot(tc, yc.getRowVector(2), new String[] {"yc2"}); //$NON-NLS-1$
canvas2.setHolding(false);
System.out.println(Messages.getString("Demo.423")); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
System.out.println("\tgp.subplot(3, 1, 3);"); //$NON-NLS-1$
System.out.println("\tgp.grid(true);"); //$NON-NLS-1$
System.out.println("\tgp.title(\"Output yo3 and yc3\");"); //$NON-NLS-1$
System.out.println("\tgp.replot(tc, yc.getRowVector(3), new String[]{\"yc3\"});"); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
Pause.pause();
canvas3.setGridVisible(true);
canvas3.setTitle("Output yo3 and yc3"); //$NON-NLS-1$
canvas3.setHolding(true);
canvas3.plot(tc, yc.getRowVector(3), new String[] {"yc3"}); //$NON-NLS-1$
canvas3.setHolding(false);
Pause.pause();
gp.close();
}
}