Demo.java
/*
* $Id: Demo.java,v 1.33 2008/07/17 13:35:52 koga Exp $
*
* Copyright (C) 2004 Koga Laboratory. All rights reserved.
*/
package org.mklab.tool.matrix;
import java.io.IOException;
import org.mklab.nfc.eig.DoubleEigenSolution;
import org.mklab.nfc.matrix.DoubleComplexMatrix;
import org.mklab.nfc.matrix.DoubleMatrix;
import org.mklab.nfc.matrix.DoublePolynomialMatrix;
import org.mklab.nfc.matrix.IntMatrix;
import org.mklab.nfc.matrix.misc.DiagonalMatrix;
import org.mklab.nfc.scalar.DoubleComplexNumber;
import org.mklab.nfc.scalar.DoubleNumber;
import org.mklab.nfc.scalar.DoublePolynomial;
import org.mklab.nfc.svd.SingularValueDecomposition;
import org.mklab.nfc.util.Pause;
import org.mklab.tool.Menu;
/**
* 行列に関するデモンストレーションを実行するクラスです。
*
* @author koga
* @version $Revision: 1.33 $
*/
public class Demo {
/**
* デモンストレーションに関するメニューを表示します。
*/
public void run() {
String title = Messages.getString("Demo.0"); //$NON-NLS-1$
String[] options = {Messages.getString("Demo.1"), // 1 //$NON-NLS-1$
Messages.getString("Demo.2"), // 2 //$NON-NLS-1$
Messages.getString("Demo.3"), // 3 //$NON-NLS-1$
Messages.getString("Demo.4"), // 4 //$NON-NLS-1$
Messages.getString("Demo.5")}; //$NON-NLS-1$
int i = 1;
for (;;) {
try {
i = Menu.menu(title, options, i);
switch (i) {
case 1:
showMatrixDescription();
break;
case 2:
showMatrixElement();
break;
case 3:
showMatrixOperation();
break;
case 4:
showMatrixFunction();
break;
default:
throw new IllegalArgumentException();
}
} catch (@SuppressWarnings("unused") IOException e) {
//
}
if (i == 0 || i == options.length) {
break;
}
}
}
/**
* 行列の記述方法について説明します。
*
* @throws IOException キーボードから入力できない場合
*/
private void showMatrixDescription() throws IOException {
System.out.println(""); //$NON-NLS-1$
System.out.println(Messages.getString("Demo.7")); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
System.out.println(Messages.getString("Demo.9")); //$NON-NLS-1$
System.out.println(Messages.getString("Demo.10")); //$NON-NLS-1$
System.out.println(Messages.getString("Demo.11")); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
System.out.println("\tMatrix A = new RealMatrix(new double[]{1,2,3});"); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
DoubleMatrix A = new DoubleMatrix(new double[] {1, 2, 3});
A.print("A"); //$NON-NLS-1$
Pause.pause();
System.out.println(""); //$NON-NLS-1$
System.out.println(Messages.getString("Demo.17")); //$NON-NLS-1$
System.out.println(Messages.getString("Demo.18")); //$NON-NLS-1$
System.out.println(Messages.getString("Demo.19")); //$NON-NLS-1$
System.out.println(Messages.getString("Demo.20")); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
System.out.println("\tA = new RealMatrix(new double[][]{{1,2,3},{4,5,6},{7,8,0}});"); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
Pause.pause();
A = new DoubleMatrix(new double[][] { {1, 2, 3}, {4, 5, 6}, {7, 8, 0}});
System.out.println(Messages.getString("Demo.24")); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
System.out.println("\tA = new RealMatrix(new double[][]{{1,2,3},"); //$NON-NLS-1$
System.out.println("\t {4,5,6},"); //$NON-NLS-1$
System.out.println("\t {7,8,0}});"); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
Pause.pause();
A.print("A"); //$NON-NLS-1$
System.out.println(Messages.getString("Demo.31")); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
System.out.println("\tComplex i = new Complex(0,1);"); //$NON-NLS-1$
System.out.println("\ti.print(\"i\");"); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
Pause.pause();
DoubleComplexNumber i = new DoubleComplexNumber(0, 1);
i.print("i"); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
System.out.println("\tMatrix F = new ComplexMatrix(new Complex[][]{{ i.add(1), i.multiply(3).add(2)},"); //$NON-NLS-1$
System.out.println("\t {i.multiply(2).add(3), i.multiply(4).add(4)}});"); //$NON-NLS-1$
System.out.println("\tF.print(\"F\");"); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
Pause.pause();
DoubleComplexMatrix F = new DoubleComplexMatrix(new DoubleComplexNumber[][] { {i.add(1), i.multiply(3).add(2)}, {i.multiply(2).add(3), i.multiply(4).add(4)}});
F.print("F"); //$NON-NLS-1$
System.out.println(Messages.getString("Demo.43")); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
System.out.println("\tnew RealMatrix(2,3)"); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
Pause.pause();
new DoubleMatrix(2, 3).print("Z(2,3)"); //$NON-NLS-1$
System.out.println(Messages.getString("Demo.48")); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
System.out.println("\tRealMatrix.I(3)"); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
Pause.pause();
DoubleMatrix.unit(3).print("I(3)"); //$NON-NLS-1$
System.out.println(Messages.getString("Demo.53")); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
System.out.println("\tRealMatrix.ONE(3)"); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
Pause.pause();
DoubleMatrix.ones(3).print("ONE(3)"); //$NON-NLS-1$
System.out.println(Messages.getString("Demo.58")); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
System.out.println("\tRealMatrix.diag(new double[]{3, 7, 2})"); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
Pause.pause();
DiagonalMatrix.create(new double[] {3, 7, 2}).print("diag(3, 7, 2)"); //$NON-NLS-1$
System.out.println(Messages.getString("Demo.63")); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
System.out.println("\tIntegerMatrix.series(1,3)"); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
Pause.pause();
IntMatrix.series(1, 3).print("[1:3]"); //$NON-NLS-1$
System.out.println(Messages.getString("Demo.68")); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
System.out.println("\tRealMatrix.series(1, 3, 0.5)"); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
Pause.pause();
DoubleMatrix.series(1, 3, 0.5).print("[1:0.5:3]"); //$NON-NLS-1$
System.out.println(Messages.getString("Demo.73")); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
System.out.println("\tIntegerMatrix.series(3, 1)"); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
Pause.pause();
IntMatrix.series(3, 1).print("[3:1]"); //$NON-NLS-1$
System.out.print(Messages.getString("Demo.78")); //$NON-NLS-1$
System.out.println(Messages.getString("Demo.79")); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
System.out.println("\tA = new RealMatrix(new double[][]{{1,2,1},{3,4,0},{0,0,1}});"); //$NON-NLS-1$
System.out.println("\tB = new RealMatrix(3,2);"); //$NON-NLS-1$
System.out.println("\tC = RealMatrix.ONE(2,3);"); //$NON-NLS-1$
System.out.println("\tD = Matrix.diag(new double[]{2,3});"); //$NON-NLS-1$
System.out.println("\tE = A.appendRight(B).appendDown(C.appendRight(D));"); //$NON-NLS-1$
System.out.println("\tE.print(\"[[A B][C D]]\");"); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
Pause.pause();
A = new DoubleMatrix(new double[][] { {1, 2, 1}, {3, 4, 0}, {0, 0, 1}});
DoubleMatrix B = new DoubleMatrix(3, 2);
DoubleMatrix C = DoubleMatrix.ones(2, 3);
DoubleMatrix D = DiagonalMatrix.create(new double[] {2, 3});
DoubleMatrix E = A.appendRight(B).appendDown(C.appendRight(D));
E.print("[[A B][C D]]"); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
Pause.pause();
}
/**
* 行列の成分の操作方法について説明します。
*
* @throws IOException キーボードから入力できない場合
*/
private void showMatrixElement() throws IOException {
System.out.println(""); //$NON-NLS-1$
System.out.println(Messages.getString("Demo.91")); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
System.out.println("\tRealMatrix A = new RealMatrix(new double[][]{{1,2,1},{3,4,0},{0,0,1}});"); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
Pause.pause();
DoubleMatrix A = new DoubleMatrix(new double[][] { {1, 2, 1}, {3, 4, 0}, {0, 0, 1}});
System.out.println(""); //$NON-NLS-1$
System.out.println(Messages.getString("Demo.96")); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
System.out.println("\tA.getElement(1,1)"); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
Pause.pause();
System.out.println("A(1,1) = " + A.getDoubleElement(1, 1)); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
System.out.println(Messages.getString("Demo.102")); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
System.out.println("\tA.getColumnVector(1)"); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
Pause.pause();
A.getColumnVector(1).print("A(:,1)"); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
System.out.println(Messages.getString("Demo.108")); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
System.out.println("\tA.getRowVector(3)"); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
Pause.pause();
A.getRowVector(3).print("A(3,:)"); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
System.out.println(Messages.getString("Demo.114")); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
System.out.println("\tA.getSubMatrix(1,2,2,3)"); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
Pause.pause();
A.getSubMatrix(1, 2, 2, 3).print("A(1:2,2:3)"); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
System.out.println(Messages.getString("Demo.120")); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
System.out.println("\tIntegerMatrix idx = new IntegerMatrix(new int[]{1,3});"); //$NON-NLS-1$
System.out.println("\tA.getRowVectors(idx)"); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
Pause.pause();
IntMatrix idx = new IntMatrix(new int[] {1, 3});
A.getRowVectors(idx).print("A(Index([1 3]),:)"); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
System.out.println(Messages.getString("Demo.127")); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
System.out.println("\tA.getSubMatrix(idx, 2, 3)"); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
Pause.pause();
A.getSubMatrix(idx, 2, 3).print("A(Index([1 3]), 2:3"); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
System.out.println(Messages.getString("Demo.133")); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
System.out.println("\tMatrix AA = new RealMatrix(3,4);"); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
Pause.pause();
DoubleMatrix AA = new DoubleMatrix(3, 4);
AA.print("AA"); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
System.out.println(Messages.getString("Demo.139")); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
System.out.println("\tAA.setElement(1,1, 1.0);"); //$NON-NLS-1$
System.out.println("\tprint AA;"); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
Pause.pause();
AA.setElement(1, 1, 1.0);
AA.print("AA"); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
System.out.println(Messages.getString("Demo.146")); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
System.out.println("\tMatrix m = new RealMatrix(new double[]{2,3});"); //$NON-NLS-1$
System.out.println("\tAA.setSubMatrix(1, 1, 3, 4, m);"); //$NON-NLS-1$
System.out.println("\tAA.print(\"AA\")"); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
Pause.pause();
DoubleMatrix m = new DoubleMatrix(new double[] {2, 3});
AA.setSubMatrix(1, 1, 3, 4, m);
AA.print("AA"); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
System.out.println(Messages.getString("Demo.154")); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
System.out.println("\tm = new RealMatrix(new double[]{4, 5, 6}).transpose();"); //$NON-NLS-1$
System.out.println("\tAA.setColumnVector(2, m);"); //$NON-NLS-1$
System.out.println("\tAA.print(\"AA\");"); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
Pause.pause();
m = new DoubleMatrix(new double[] {4, 5, 6}).transpose();
AA.setColumnVector(2, m);
AA.print("AA"); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
System.out.println(Messages.getString("Demo.162")); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
System.out.println("\tm = new RealMatrix(new double[][]{{7,8},{9,10}});"); //$NON-NLS-1$
System.out.println("\tAA.setSubMatrix(2,3,3,4,m);"); //$NON-NLS-1$
System.out.println("\tAA.print(\"AA\");"); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
Pause.pause();
m = new DoubleMatrix(new double[][] { {7, 8}, {9, 10}});
AA.setSubMatrix(2, 3, 3, 4, m);
AA.print("AA"); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
Pause.pause();
}
/**
* 行列の演算に関して説明します。
*
* @throws IOException キーボードから入力できない場合
*/
private void showMatrixOperation() throws IOException {
System.out.println(""); //$NON-NLS-1$
System.out.println(Messages.getString("Demo.171")); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
Pause.pause();
System.out.println(""); //$NON-NLS-1$
System.out.println(Messages.getString("Demo.174")); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
System.out.println("\tMatrix A = new RealMatrix(new double[][]{{1,2,3},{4,5,6},{7,8,0}});"); //$NON-NLS-1$
System.out.println("\tMatrix B = new RealMatrix(new double[][]{{8,1,6},{3,5,7},{4,9,2}});"); //$NON-NLS-1$
System.out.println("\tA.add(B)"); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
Pause.pause();
DoubleMatrix A = new DoubleMatrix(new double[][] { {1, 2, 3}, {4, 5, 6}, {7, 8, 0}});
DoubleMatrix B = new DoubleMatrix(new double[][] { {8, 1, 6}, {3, 5, 7}, {4, 9, 2}});
A.add(B).print("A + B"); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
System.out.println("\tA.subtract(B)"); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
Pause.pause();
A.subtract(B).print("A - B"); //$NON-NLS-1$
System.out.println(Messages.getString("Demo.6")); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
System.out.println("\tA.multiply(B)"); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
Pause.pause();
A.multiply(B).print("A * B"); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
System.out.println("\tMatrix C = new RealMatrix(new double[][]{{1,2,3},{3,2,5}});"); //$NON-NLS-1$
System.out.println("\tMatrix D = new RealMatrix(new double[][]{{3,1,6},{3,5,7},{4,9,1}});"); //$NON-NLS-1$
System.out.println("\tC.multiply(D)"); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
Pause.pause();
DoubleMatrix C = new DoubleMatrix(new double[][] { {1, 2, 3}, {3, 2, 5}});
DoubleMatrix D = new DoubleMatrix(new double[][] { {3, 1, 6}, {3, 5, 7}, {4, 9, 1}});
C.multiply(D).print("C * D"); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
System.out.println(Messages.getString("Demo.197")); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
System.out.println("\tMatrix Ai = A.inverse()"); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
Pause.pause();
DoubleMatrix Ai = A.inverse();
Ai.print("A~"); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
System.out.println("\tA.multiply(Ai)"); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
Pause.pause();
A.multiply(Ai).print("A * Ai"); //$NON-NLS-1$
System.out.println(Messages.getString("Demo.206")); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
System.out.println("\tA.divide(B)"); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
Pause.pause();
A.divide(B).print("A / B"); //$NON-NLS-1$
System.out.println(Messages.getString("Demo.211")); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
System.out.println("\tB.leftDivide(A)"); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
Pause.pause();
B.leftDivide(A).print("B \\ A"); //$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 At = A.transpose()"); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
Pause.pause();
DoubleMatrix At = A.transpose();
At.print("A'"); //$NON-NLS-1$
System.out.println(Messages.getString("Demo.222")); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
System.out.println("\tC = new ComplexMatrix(A,B)"); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
Pause.pause();
DoubleComplexMatrix E = new DoubleComplexMatrix(A, B);
E.print("(A,B)"); //$NON-NLS-1$
System.out.println(Messages.getString("Demo.227")); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
System.out.println("\tMatrix Ec = E.conjugateTranspose()"); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
Pause.pause();
DoubleComplexMatrix Ec = E.conjugateTranspose();
Ec.print("E#"); //$NON-NLS-1$
System.out.println(Messages.getString("Demo.232")); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
System.out.println(Messages.getString("Demo.234")); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
System.out.println("\tMatrix AB = A.multiplyElementWise(B)"); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
Pause.pause();
DoubleMatrix AB = A.multiplyElementWise(B);
AB.print("A .* B"); //$NON-NLS-1$
System.out.println(Messages.getString("Demo.239")); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
System.out.println("\tA.divideElementWise(B)"); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
Pause.pause();
A.divideElementWise(B).print("A ./ B"); //$NON-NLS-1$
System.out.println(Messages.getString("Demo.244")); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
System.out.println("\tA.powerElementWise(0.3)"); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
Pause.pause();
A.powerElementWise(0.3).print("A .^ 0.3"); //$NON-NLS-1$
}
/**
* 行列関数について説明します。
*
* @throws IOException キーボードから入力できない場合
*/
private void showMatrixFunction() throws IOException {
System.out.println(""); //$NON-NLS-1$
System.out.println(Messages.getString("Demo.250")); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
Pause.pause();
System.out.println(""); //$NON-NLS-1$
System.out.println(Messages.getString("Demo.253")); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
System.out.println("\tRealMatrix A = new RealMatrix(new double[][]{{1,2,3},{4,5,6},{7,8,0}});"); //$NON-NLS-1$
System.out.println("\tA.determinant()"); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
Pause.pause();
DoubleMatrix A = new DoubleMatrix(new double[][] { {1, 2, 3}, {4, 5, 6}, {7, 8, 0}});
System.out.println("det(A) = " + A.determinant()); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
System.out.println(Messages.getString("Demo.260")); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
System.out.println("\tA.trace()"); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
Pause.pause();
System.out.println("trace(A) = " + A.trace()); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
System.out.println(Messages.getString("Demo.266")); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
System.out.println("\t((NumericalMatrix)A).rank()"); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
Pause.pause();
System.out.println("rank(A) = " + A.rank()); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
System.out.println(Messages.getString("Demo.272")); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
System.out.println("\tA.cond()"); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
Pause.pause();
System.out.println("cond(A) = " + A.conditionNumber()); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
System.out.println(Messages.getString("Demo.278")); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
System.out.println("\tA.exp()"); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
Pause.pause();
A.exp().print("exp(A)"); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
System.out.println(Messages.getString("Demo.284")); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
System.out.println("\tA.sinElementWise()"); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
Pause.pause();
A.sinElementWise().print("sin(Array(A))"); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
System.out.println(Messages.getString("Demo.290")); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
System.out.println("\tA.expElementWise()"); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
Pause.pause();
A.expElementWise().print("exp(Array(A))"); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
System.out.println(Messages.getString("Demo.296")); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
System.out.println("\tMatrix d = A.eigenValue();"); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
Pause.pause();
DoubleComplexMatrix d = A.eigenValue();
d.print("eigval(A)"); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
System.out.println(Messages.getString("Demo.302")); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
System.out.println("\tMatrix[] DV = A.eigenDecompose();"); //$NON-NLS-1$
System.out.println("\tMatrix D = DV[0].getRealPart();"); //$NON-NLS-1$
System.out.println("\tMatrix V = DV[1].getRealPart();"); //$NON-NLS-1$
System.out.println("\tD.print(\"D\");"); //$NON-NLS-1$
System.out.println("\tV.print(\"V\");"); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
Pause.pause();
DoubleEigenSolution DV = A.eigenDecompose();
DoubleComplexMatrix D = new DoubleComplexMatrix(DV.getRealValue(), DV.getImagValue());
DoubleComplexMatrix V =new DoubleComplexMatrix(DV.getRealVector(), DV.getImagVector());
D.print("D"); //$NON-NLS-1$
V.print("V"); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
System.out.println(Messages.getString("Demo.313")); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
System.out.println("\tMatrix A = new RealMatrix(new double[][]{{1,2,3},{4,5,6},{7,8,0}});"); //$NON-NLS-1$
System.out.println("\tMatrix B = new RealMatrix(new double[][]{{8,1,6},{3,5,7},{4,9,2}});"); //$NON-NLS-1$
System.out.println("\tDV = A.eigenDecompose(B);"); //$NON-NLS-1$
System.out.println("\tD = DV[0];"); //$NON-NLS-1$
System.out.println("\tV = DV[1];"); //$NON-NLS-1$
System.out.println("\tD.print(\"D\");"); //$NON-NLS-1$
System.out.println("\tV.print(\"V\");"); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
Pause.pause();
A = new DoubleMatrix(new double[][] { {1, 2, 3}, {4, 5, 6}, {7, 8, 0}});
DoubleMatrix B = new DoubleMatrix(new double[][] { {8, 1, 6}, {3, 5, 7}, {4, 9, 2}});
DoubleEigenSolution DV2 = A.eigenDecompose(B);
D = new DoubleComplexMatrix(DV2.getRealValue(), DV2.getImagValue());
V = new DoubleComplexMatrix(DV2.getRealVector(), DV2.getImagVector());
D.print("D"); //$NON-NLS-1$
V.print("V"); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
System.out.println(Messages.getString("Demo.326")); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
System.out.println("\tMatrix[] UDV = A.singularValueDecompose();"); //$NON-NLS-1$
System.out.println("\tMatrix U = UDV[0];"); //$NON-NLS-1$
System.out.println("\tD = UDV[1];"); //$NON-NLS-1$
System.out.println("\tV = UDV[2];"); //$NON-NLS-1$
System.out.println("\tU.print(\"U\");"); //$NON-NLS-1$
System.out.println("\tD.print(\"D\");"); //$NON-NLS-1$
System.out.println("\tV.print(\"V\");"); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
Pause.pause();
SingularValueDecomposition<DoubleNumber,DoubleMatrix> UDV = A.singularValueDecompose();
DoubleMatrix U = UDV.getU();
DoubleMatrix Dre = UDV.getD();
DoubleMatrix Vre = UDV.getV();
U.print("U"); //$NON-NLS-1$
Dre.print("D"); //$NON-NLS-1$
Vre.print("V"); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
System.out.println(Messages.getString("Demo.340")); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
System.out.println("\tPolynomial s = new DoublePolynomial(\"s\");"); //$NON-NLS-1$
System.out.println("\tPolynomial phi = ((DoublePolynomialMatrix) (s.multiply(RealMatrix.I(A)).subtract(A))).determinant();"); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
Pause.pause();
DoublePolynomial s = new DoublePolynomial("s"); //$NON-NLS-1$
DoublePolynomial phi = new DoublePolynomialMatrix(DoubleMatrix.unit(A)).multiply(s).subtract(new DoublePolynomialMatrix(A)).determinant();
phi.print("det(s*I(A) - A"); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
System.out.println(Messages.getString("Demo.348")); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
System.out.println("\tphi.roots()"); //$NON-NLS-1$
System.out.println("\tA.eigenValue()"); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
Pause.pause();
phi.getRoots().print("roots(phi)"); //$NON-NLS-1$
A.eigenValue().print("eigval(A)"); //$NON-NLS-1$
System.out.println(""); //$NON-NLS-1$
Pause.pause();
}
}