01 /*
02 * $Id: Semilogx.java,v 1.19 2008/02/02 05:53:03 koga Exp $
03 *
04 * Copyright (C) 2004 Koga Laboratory. All rights reserved.
05 *
06 */
07 package matxbook.chap12;
08
09 import java.io.IOException;
10
11 import org.mklab.nfc.matrix.DoubleComplexMatrix;
12 import org.mklab.nfc.matrix.DoubleMatrix;
13 import org.mklab.nfc.matrix.misc.LogarithmicallySpacedVector;
14 import org.mklab.nfc.scalar.DoubleComplexNumber;
15 import org.mklab.nfc.scalar.Polynomial;
16 import org.mklab.nfc.scalar.RationalPolynomial;
17 import org.mklab.nfc.util.Pause;
18 import org.mklab.tool.graph.gnuplot.Canvas;
19 import org.mklab.tool.graph.gnuplot.Gnuplot;
20
21
22 /**
23 * 片対数グラフのサンプルです。
24 * @author koga
25 * @version $Revision: 1.19 $, 2004/05/01
26 */
27 public class Semilogx {
28
29 /**
30 * メインメソッド
31 *
32 * @param args コマンドライン引数
33 * @throws InterruptedException 強制終了された場合
34 * @throws IOException キーボードから入力できない場合
35 */
36 @SuppressWarnings("nls")
37 public static void main(String[] args) throws InterruptedException, IOException {
38 Polynomial s = new Polynomial("s");
39 DoubleComplexNumber j = new DoubleComplexNumber(0, 1);
40 DoubleMatrix w = LogarithmicallySpacedVector.create(-2.0, 3.0);
41 RationalPolynomial G = s.add(1).inverse();
42 DoubleComplexMatrix Gjw = (DoubleComplexMatrix)G.evaluateElementWise(w.multiply(j));
43 DoubleMatrix g = ((DoubleMatrix)Gjw.absElementWise()).log10ElementWise().multiply(20);
44 DoubleMatrix p = ((DoubleMatrix)Gjw.argumentElementWise()).multiply(180 / Math.PI);
45
46 Gnuplot gnuplot1 = new Gnuplot();
47 Canvas canvas1 = gnuplot1.createCanvas();
48 canvas1.semilogx(w, g, new String[] {"gain"});
49
50 Gnuplot gnuplot2 = new Gnuplot();
51 Canvas canvas2 = gnuplot2.createCanvas();
52 canvas2.semilogx(w, p, new String[] {"phase"});
53
54 Pause.pause();
55 gnuplot1.close();
56 gnuplot2.close();
57 }
58 }
|