%=====================================================================
% 秋田高専 2E 情報工学概論 テキスト
%　　テーマ 浮動小数点と数値計算
%    本テキストの内容
%        ・
%        ・
%        ・
%        ・
%　　　 　・
%
% last updated 2006.2.5
%    created by  Masashi Yamamoto
%     e-mail yamamoto@akita-nct.jp
%=====================================================================
\documentclass[10pt,a4paper]{jarticle}
\usepackage{graphicx,amsmath,amssymb,ascmac,float}
\usepackage{html, listings, jlisting}
\usepackage{url}
\oddsidemargin 0mm  %左の余白 25.4mm-0mm　奇数ページ
\evensidemargin 0mm %左の余白 25.4mm-0mm　偶数ページ
\textwidth 160mm
\newcommand{\command}[1]{「\texttt{#1}」}
\newcommand{\cl}[1]{\texttt{#1}}
\newcommand{\tw}[1]{\texttt{#1}}
%
\newcounter{toi_num}
\newcommand{\toi}{\textbf{\texttt [問\arabic{toi_num}]}
   \addtocounter{toi_num}{1}}
%
\newcommand{\qbox}[2]{
{\fboxsep=0pt \fboxrule=0.4pt\fbox{\hspace{#1}#2\hspace{#1}}}
}
%
\renewcommand{\lstlistingname}{リスト}
\lstset{language=C,%
        basicstyle=\footnotesize,%
        commentstyle=\textit,%
        classoffset=1,%
        keywordstyle=\bfseries,%
	frame=tRBl,framesep=5pt,%
	showstringspaces=false,%
        numbers=left,stepnumber=1,numberstyle=\footnotesize%
	}%
%
\begin{htmlonly}
\usepackage{verbatimfiles}
 \providecommand{\lstinputlisting}[2][]{\verbatimlisting{#2}}
\end{htmlonly}
%
\begin{document}
\title{gunplotによるグラフ作成}
\author{山本昌志\thanks{独立行政法人　秋田工業高等専門学校　電気情報工学科}}
\date{2006年2月13日}
\maketitle
%
%
%=====================================================================
\section{本日の学習内容}
%=====================================================================
本日は教科書を離れて，グラフの作成方法を学習する．技術者や科学技術の研究者は，情
報を目に見える形で示すためにグラフを多用する．現象の分析や，その現象が物語ってい
ることを伝えるためにグラフが使う．また，諸君は今後の学習で大量のグラフを書かなく
てはならない．実験のデータ整理もあるが，数学や専門科目の理解を深めるためにはグラ
フを書き，現象を視覚でとらえることが重要となる．そうしないと，なかなか自然現象の
理解は深まらない．そこで，本日はコンピューターを使ったグラフの作成方法を学習する．

ここでのグラフの作成には，世界中で最も使われている{\bf gnuplot}というソフトウェ
アーを使う．本日の学習内容は，以下の通りである．
\begin{itemize}
 \item gnuplot を使ったグラフ作成方法
 \item C言語を通しての gnuplot の操作方法
\end{itemize}
%
他にも，グラフ作成ソフトウェアーはたくさんあるし，グラフィックライブラリーを使う
こともできる．興味のある者は調べると面白いだろう．
%
%
%=====================================================================
\section{グラフ作成}
%=====================================================================
%---------------------------------------------------------------------
\subsection{gnuplotとは}
%---------------------------------------------------------------------
gnuplotは簡単に2D，3Dのグラフが作成できるフリーのソフトウェーである．単純なグラ
フから，学術論文用の高品質なグラフまで作成可能で，広く普及している．名前にgnu
とついているが，まぎらわしいことに，Free Software Foundation (FSF)が進めている
GNUプロジェクト\footnote{Unixに似た フリーソフトウェアの完全なオペレーティングシ
ステムの作成を目指す．}とは関係が無い．gunplotの読み方は「ニュープロット(あるい
は，ヌープロット)」ではあるが，「グニュープロット」と呼ばれることも多い．

gnuplotはUNIXに限らずWindowsやMachintoshでも動作し，Excelとくらべものにならない
くらい美しいグラフを作成することができる．しかも，フリーである．諸君は実験実習の
グラフ作成に使うのが良いだろう．実験実習程度のグラフならExcelでも作成可能ではあ
るが，そのグラフは醜く，とても科学技術の報告書や論文に載せるクオリティに達してい
ない．gnuplotは，C言語などプログラミング言語と組み合わせて使うと，様々な処理が自
動的にできる．そのようなことから，私はコンピュータープログラムによる数値計算の結
果の表示に使っている．

マニュアル類はwebにたくさんある．情報が必要になれば，以下のサイトを調べるのが
良いだろう．
\begin{quote}
\htmladdnormallink{http://t16web.lanl.gov/Kawano/gnuplot/}{http://t16web.lanl.gov/Kawano/gnuplot/}

\htmladdnormallink{http://lagendra.s.kanazawa-u.ac.jp/ogurisu/manuals/gnuplot-intro/}{http://lagendra.s.kanazawa-u.ac.jp/ogurisu/manuals/gnuplot-intro/}
\end{quote}
%
%---------------------------------------------------------------------
\subsection{起動と終了}
%---------------------------------------------------------------------
簡単な操作方法を述べるが，本当は，先ほど示したwebページを見て各自学習する方が良
い．まずは，gunplotを立ち上げてみよう．以下のコマンドを端末に入力する．
%
\begin{quote}\vspace{-2mm}
 \begin{verbatim}
	$ gnuplot
 \end{verbatim}
\end{quote}\vspace{-7mm}
%
すると，gnuplotが立ち上がり，コマンド入力画面になる．終了したい場合は，
%
\begin{quote}\vspace{-2mm}
 \begin{verbatim}
	gnuplot> exit
 \end{verbatim}\vspace{-7mm}
\end{quote}
とする．
%
%---------------------------------------------------------------------
\subsection{2次元グラフ}
%---------------------------------------------------------------------
まずは，三角関数のグラフを書いてみよう．以下のコマンドを入力する．
%
\begin{quote}\vspace{-2mm}
 \begin{verbatim}
	gnuplot> plot sin(x)
 \end{verbatim}
\end{quote}\vspace{-7mm}
%
$\sin$関数のグラフが描けただろう．描画範囲を変えたい場合は，
%
\begin{quote}\vspace{-2mm}
 \begin{verbatim}
	gnuplot> plot [0:6.28] [-1.5:1.5] sin(x)
 \end{verbatim}
\end{quote}\vspace{-7mm}
%
とする．同時に複数のグラフを各場合は，次のように関数を並べればよい．
%
\begin{quote}\vspace{-2mm}
 \begin{verbatim}
	gnuplot> plot [-6.28:6.28] [-1.5:1.5] sin(x),cos(x),tan(x)
 \end{verbatim}
\end{quote}\vspace{-7mm}
次のようにすると様々なグラフが描ける．
\begin{quote}\vspace{-2mm}
 \begin{tabular}{p{70mm}l}
  \tw{gnuplot> plot x**3+x+1} & $x^3+x+1$ \\
  \tw{gnuplot> plot x**0.5} & $x^{0.5}$ \\
  \tw{gnuplot> plot log(x)} & $\log_e(x)$ \\
  \tw{gnuplot> plot log10(x)} & $\log_{10}(x)$ \\
  \tw{gnuplot> plot real(exp(\{0,1\}*x)}) & $\Re{(e^{ix}})$\\
  \tw{gnuplot> plot sqrt(x)} & $\sqrt{x}$
 \end{tabular}
\end{quote}
さらに，定義した関数のグラフを書くこともできる．
\begin{quote}\vspace{-2mm}
 \begin{tabular}{p{70mm}l}
  \tw{gnuplot> f(x)=sin(x)} \\
  \tw{gnuplot> g(x)=cos(x)} \\
  \tw{gnuplot> plot f(x)+g(x), f(x)*g(x)} \\
 \end{tabular}
\end{quote}

\fbox{練習問題}
\begin{quote}
 \begin{itemize}
  \item[\textbf{[練習1]}]以下の関数のグラフを作成せよ．
			 \begin{align*}
			  & \sin(x)\cos(x) &
			  & \sin^2(x) &
			  & \sin(x)+\cos(x) & \\
			  &xe^{-x}&
			  &x-\frac{x^3}{6}+\frac{x^5}{120}-\frac{x^7}{5040} &
			  &\cos(x),\,\sin(x)&  \\
			 \end{align*}
 \end{itemize}
\end{quote}

gunplotには付録の表\ref{table:gunplot_include_math_func}のような関数が用意されて
いる．普通に使う関数はほとんど用意されているし，複素数もサポートされている．複素
数は，\tw{{実数部，虚数部}}のように記述する．すなわち，
\begin{quote}\vspace{-2mm}
 \begin{tabular}{p{40mm}l}
  \tw{gnuplot> \{1,0\}} & 実数の1を表す． \\
  \tw{gnuplot> \{0,1\}} & 虚数単位$i$を表す． \\
  \tw{gnuplot> \{5.3,6.8\}} & $5.3+6.8i$を表す．
 \end{tabular}
\end{quote}\vspace{-2mm}
である．
%
%---------------------------------------------------------------------
\subsection{3次元グラフ}
%---------------------------------------------------------------------
3次元グラフも簡単にかける．3次元グラフの場合，右マウスでドラッグすると視点を変え
ることができるのでおもしろい．
%
\begin{quote}\vspace{-2mm}
 \begin{tabular}{p{50mm}l}
  \tw{gnuplot> splot x**2+y**2} & $x^2+y^2$  \\
  \tw{gnuplot> splot x*sin(x+y)} & $x\sin(x+y)$  \\
 \end{tabular}
\end{quote}
%

3次元グラフで隠線処理が必要であれば，\tw{set hidden3d}とする．また，表示するデー
タ点は，\tw{set isosample}で設定する．たとえば，以下のようにすれば，隠線処理し，x方向とy方向とも40点のデータを出力する．
%
\begin{quote}\vspace{-2mm}
 \begin{verbatim}
	gnuplot> set hidden3d
	gnuplot> set isosample 40,40
	gnuplot> splot 1/(x*x+y*y+5)*cos(0.1*(x*x+y*y))
 \end{verbatim}
\end{quote}
%
%
%---------------------------------------------------------------------
\subsection{媒介変数表示}
%---------------------------------------------------------------------
媒介変数を使ったグラフの作成もできる．
\begin{quote}\vspace{-2mm}
 \begin{verbatim}
	gnuplot> set parametric
	gnuplot> plot sin(5*t), cos(2*t+pi/2)
 \end{verbatim}
\end{quote}\vspace{-7mm}
媒介変数表示を止めるためには，
\begin{quote}\vspace{-2mm}
 \begin{verbatim}
	gnuplot> unset parametric
 \end{verbatim}
\end{quote}\vspace{-7mm}
とする．
%
%---------------------------------------------------------------------
\subsection{ファイルのデータの描画}
%---------------------------------------------------------------------
ファイルに格納されたデータをグラフ表示することもできる．講義では，三角関数の値
が格納されたデータをダウンロードして，それをグラフにする．表の各行には，
$\theta$と$\sin\theta$，$\cos\theta$，$\tan\theta$の値が書き込まれている．
このファイルのデータをグラフ化するときには，\tw{plot}コマンドを使う．
引き続いて，ダブルクォーテーションでファイル名を囲む．最後に，\tw{using}を使って
x座標とy座標が書かれている列を示す．具体的には，
%
\begin{quote}\vspace{-2mm}
 \begin{verbatim}
	gnuplot> plot "trifunc.txt" using 1:2
 \end{verbatim}
\end{quote}\vspace{-7mm}
%
である．各データ点を線で結びたければ，
%
\begin{quote}\vspace{-2mm}
 \begin{verbatim}
	gnuplot> plot "trifunc.txt" using 1:2 with line
 \end{verbatim}
\end{quote}\vspace{-7mm}
%
とする．複数のデータを一度に描くためには，
%
\begin{quote}\vspace{-2mm}
 \begin{verbatim}
	gnuplot> plot "trifunc.txt" using 1:2 with line, 
                        "trifunc.txt" using 1:3 with line,
                        "trifunc.txt" using 1:4 with line 
 \end{verbatim}
\end{quote}\vspace{-7mm}
%
とする．ただし，改行しないで(Enterキーを押さない)記述する必要がある．これでは，
$\tan(x)$の値が大きすぎるので，プロットす
るレンジを変える．以下のように\tw{set xrange[ymin:ymax]}でレンジを変えて，
\tw{replot}コマンドをつかう．
%
\begin{quote}\vspace{-2mm}
 \begin{verbatim}
	gnuplot> set yrange[-1.5:1.5]
	gnuplot> replot 
 \end{verbatim}
\end{quote}
%
%---------------------------------------------------------------------
\subsection{グラフのファイル出力}
%---------------------------------------------------------------------
%-------------------------
\subsubsection{出力先の変更}
%-------------------------
gnuplotはディスプレイのみならず，グラフの図形ファイルを作成することができる．デ
フォルトの出力先はディスプレイとなっているので，これまでのグラフは画面に描画され
た．ディスプレイに表示されるだけでは不便なので，図形ファイルを作成する方法を示す．

諸君が使う代表的な出力先やファイルフォーマットを表\ref{table:set_terminal_fomat}
に示す．ディスプレイからファイルに出力先を変更するには，次のようにする．
\begin{quote}\vspace{-2mm}
 \begin{verbatim}
	gnuplot> set terminal emf
	gnuplot> set output "hogehoge.emf"
 \end{verbatim}
\end{quote}\vspace{-7mm}
これは，出直先をemfフォーマットのファイルに変更して，ファイル名を hogehoge.emf としてい
る．

\begin{table}[H]
 \caption{\tw{代表的な出力デバイスとフォーマットを表すset terminal オプション}}
 \label{table:set_terminal_fomat}
 \begin{center}
  \begin{tabular}{ll}
   \hline
   \multicolumn{1}{c}{出力先} & \multicolumn{1}{c}{説明} \\
   \hline \hline
   \tw{x11} & UNIXのディスプレイ\\
   \tw{windows} & Windowsのディスプレイ \\
   \tw{emf} & Windowsでよく使われるデータのフォーマット\\
   \tw{postscript} & UNIXで使われるデータフォーマット\\
   \tw{gif} & webなどでおなじみ \\
   \tw{png} & これもwebなどでおなじみ \\
   \tw{epslatex} & \LaTeX を使う場合便利 \\
   \hline
  \end{tabular}
 \end{center}
\end{table}
%--------------------------------
\subsubsection{MS wordに貼り付ける}
%--------------------------------
gnuplotで作成したグラフをMS Wordに貼り付ける時は，Windows 標準の emf フォーマッ
トが便利である．emf フォーマットのグラフは次のようにして作成する．
\begin{quote}\vspace{-2mm}
 \begin{verbatim}
	gnuplot> set terminal emf
	gnuplot> set output "hoge.emf"
	gnuplot> plot sin(x)
 \end{verbatim}
\end{quote}\vspace{-7mm}
最初の行で，出力先を emf ファイルに指定している．次の行で，出力ファイル名を
\tw{hoge.emf}としている．拡張子は重要で，\tw{emf} としなくてはならない．プログラ
ムは拡張子でファイルの種類を判断しているからである．最後の行で，三角関数のグラフ
を作成している．これで，正弦関数が書かれたファイル \tw{hoge.emf} ができあがる．

これを MS Word に貼り付けるのは簡単である．
\begin{itemize}
 \item Wordを立ち上げて，メニューの挿入$\rightarrow$図$\rightarrow$ファイルから
       を選択する．
 \item ファイルを選択する．
\end{itemize}

もし，emfフォーマットで張り付けができなければ，他のフォーマットを試してみる．
%
%------------------------------------
\subsubsection{Starsuite に貼り付ける}
%------------------------------------
学校のLinuxでは，office 環境として Sun microsystems の Starsuite が使えるように
なっている．Starsuite へのグラフの張り付けもほとんど，MS Word と同じである．ここ
ではあえて説明しないので，各自，実施して見よ．
%
%--------------------------------
\subsubsection{\LaTeX に貼り付ける}
%--------------------------------
\LaTeX というすばらしい文書作成ソフトウェアーがある．使い方はちょっと難しいが，長
い文書を作成する時は楽だし，なによりも出来上がりがすばらしい．本年度，諸君に配布
した講義ノートは全て\LaTeX を使っている．以下のようにしてグラフのファイルを作成
する．
\begin{quote}\vspace{-2mm}
 \begin{verbatim}
	gnuplot> set terminal epslatex
	gnuplot> set output "hoge.eps"
	gnuplot> plot sin(x)
 \end{verbatim}
\end{quote}\vspace{-7mm}

そうすると，hoge.eps と hoge.tex というファイルができあがるので，それを\LaTeX の
ソースに以下のように組み込めばよい．
\begin{quote}\vspace{-2mm}
 \setlength{\baselineskip}{12pt}
 \begin{verbatim}
\documentclass[10pt,a4paper]{jarticle}
\usepackage{graphicx}
\begin{document}

\begin{figure}[hbtp]
  \input{hoge}
  \caption{三角関数のグラフ}
\end{figure}

\end{document}
 \end{verbatim}
\end{quote}\vspace{-7mm}
%=====================================================================
\section{gnuplotのコマンド}
%=====================================================================
%---------------------------------------------------------------------
\subsection{ヘルプ}
%---------------------------------------------------------------------
gnuplotにはかなり詳しいヘルプがある．英文であることと，コマンド入力のため初心者
には使いにくいと思うが，使い込むとかなり便利である．ヘルプモードに入るためには，
\begin{quote}\vspace{-2mm}
 \begin{verbatim}
	gnuplot> help
 \end{verbatim}
\end{quote}\vspace{-7mm}
とする．また，コマンドについて調べたければ，
\begin{quote}\vspace{-2mm}
 \begin{verbatim}
	gnuplot> help plot
 \end{verbatim}
\end{quote}\vspace{-7mm}
のように，\tw{help}の後にコマンド名を書く．

webページの方が圧倒的に分かり易いが，ネットに接続されていない環境の場合やコマン
ドの使い方を忘れた場合には，かなり重宝する．
%---------------------------------------------------------------------
\subsection{各種コマンド}
%---------------------------------------------------------------------
gnuplotはターミナルにコマンドを打ち込んで，動作させる．使えるコマンドを，付録の
表\ref{table:gunplot_commands}に示しておく．
%
%---------------------------------------------------------------------
\subsection{便利な機能}
%---------------------------------------------------------------------
\paragraph{カレントディレクトリーの表示}シェルと同じ\tw{pwd}コマンドが使える．
\begin{quote}\vspace{-2mm}
 \begin{verbatim}
	gnuplot> pwd
 \end{verbatim}
\end{quote}\vspace{-7mm}
%
\paragraph{ディレクトリーの移動}シェルと同じ\tw{cd}コマンドが使える．
\begin{quote}\vspace{-2mm}
 \begin{verbatim}
	gnuplot> cd "/home/yamamoto/hoge"
	gnuplot> cd ".."
 \end{verbatim}
\end{quote}\vspace{-7mm}
%
\paragraph{ヒツトリー}キーボードの上矢印($\uparrow$)や下矢印($\downarrow$)でヒス
	トリー機能が使える．
\begin{quote}\vspace{-2mm}
 \begin{verbatim}
	gnuplot> 矢印
 \end{verbatim}
\end{quote}\vspace{-7mm}
%
\paragraph{シェルコマンド}\tw{!}を付ければシェルコマンドが使える．
\begin{quote}\vspace{-2mm}
 \begin{verbatim}
	gnuplot> !ls
 \end{verbatim}
\end{quote}\vspace{-7mm}

%=====================================================================
\section{C言語からgnuplotを操作する}
%=====================================================================
%---------------------------------------------------------------------
\subsection{パイプラインとは}
%---------------------------------------------------------------------
gnuplotをC言語のプログラムから制御するには，パイプを使うのが最も簡単である．C言語の
プログラムで，パイプを開いて，それをgnuplotに接続するのである．接続方法を説明す
る前に，UNIXのパイプと言う機能を簡単に説明しておく．

UNIXのコマンドの大部分は，標準入力(キーボード)からデータを受け取り，標準出力(ディ
スプレイ) に処理した結果を出力するようになっている．例えば，
%
\begin{quote}\vspace{-2mm}
 \begin{verbatim}
	ls -l
 \end{verbatim}
\end{quote}\vspace{-7mm}
%
などである．このように，コマンドをフィルターと呼ぶ．

複数のコマンドを使って，処理したいデータがある場合，UNIXではコマンドを接続するこ
とができる．標準出力から出てくるデータを次のコマンドの標準入力に渡すのである．例
えば，
%
\begin{quote}\vspace{-2mm}
 \begin{verbatim}
	ls -l | sort -n +4
 \end{verbatim}
\end{quote}\vspace{-7mm}
%
のようにするのである．最初のコマンドで，カレントディレクトリーのファイルとディレ
クトリーの情報を調べ，次のコマンドでファイル容量の順に並べている．

このようにコマンドを連結する機能をパイプラインという．そして，連結する \tw{|} を
パイプという．あたかも，パイプにデータが流れているかのようである．もちろん，2個
以上のコマンドの連結が可能である．このようにパイプを使ってコマンドをつなぐことに
より，UNIXではかなり複雑な動作も簡単に記述できる．
%
%---------------------------------------------------------------------
\subsection{パイプを使う方法}
%---------------------------------------------------------------------
パイプを使うことにより，C言語のプログラムを通してgnuplotを制御することができる．
パイプを通してC言語のプログラムから，gnuplotにコマンドを流して，プログラマーの思
い通りに動作させることが可能である．これを実現するためには，
\begin{itemize}
 \item パイプを開く
 \item パイプを通してコマンドを送る
 \item パイプを閉じる
\end{itemize}
の操作が必要である．

パイプを開くためには，ファイルポインターをつかう．そのためファイルポインターを格
納すの変数を用意しなくてはならない．パイプの先もファイルとして扱われるのである．
\begin{quote}\vspace{-2mm}
 \tw{FILE *hoge;}
\end{quote}

次にgnuplotを立ち上げて，そこにパイプを接続する必要がある．パイプの情報のファイ
ルポインターで示される．
\begin{quote}\vspace{-2mm}
 \tw{hoge = popen("gnuplot -persist","w");}
\end{quote}
\tw{popen()}関数がパイプを開く命令である．これで，gnuplot が立ち上がり，パイプを
通して，コマンドを送ることができる．オプションの\tw{persist}で，gnuplotが終了し
てもグラフが残るようにしている．そうしないと，コンピューターの動作は高速なので，
gunplotは一瞬にして終了し，グラフが消えてしまい，ほとんど動作内容が分からなく
なる．

パイプを通して，gnuplotにコマンドを送るのは\tw{fprintf()}関数を使う．
\begin{quote}\vspace{-2mm}
  \tw{fprintf(hoge, "plot sin(x)\textbackslash n");}
\end{quote}
この\tw{fprintf}を使って，gnuplotにいくらでもコマンドを送ることができる．あたか
も，C言語の向こう側でgnuplotが立ち上がって，それから命令を送っているかのように動
作する．このようなことができるのが，コマンドを打ち込むCharacter-based User Interface(CUI)の良いところである．

すべての動作が終了したならば，パイプを閉じなくてはならない．これは，ファイルの操
作と全く同じである．
\begin{quote}\vspace{-2mm}
  \tw{pclose(hoge);}
\end{quote}\vspace{-2mm}
%
%---------------------------------------------------------------------
\subsection{プログラム例}
%---------------------------------------------------------------------
%-------------------------
\subsubsection{グラフ作成}
%-------------------------
先に示した方法で，C言語からgnuplotを制御して，三角関数のグラフを作成するプログラ
ムをリスト\ref{prog:sin_c}に示す．
%
\lstinputlisting[caption=パイプを使いC言語からgnuplotを制御している．,label=prog:sin_c]
{program/sin.c}

%-------------------------------------
\subsubsection{データファイルとグラフ作成}
%-------------------------------------
複雑な数値計算を行う場合，データを作成してから，それをグラフ化することがしばしば
ある．次に，インパルスのデータを作成した後，グラフ化する例をリスト\ref{prog:impluse_c}に示す．
%
\lstinputlisting[caption=パイプを使いC言語からgnuplotを制御している．,label=prog:impluse_c]
{program/impulse.c}

%---------------------------------------
\subsubsection{\tw{set}コマンドを使った例}
%---------------------------------------
もう少し複雑な，\tw{set}コマンドを駆使した例をリスト\ref{prog:gnuplot}に示す．
%
\lstinputlisting[caption=パイプを使ったgnuplotの制御．データファイルを作成して，
それをプロットしている．軸なども細かく制御している．,label=prog:gnuplot]
{program/gnuplot.c}
%
\newpage
%=====================================================================
\section{付録}
%=====================================================================
%---------------------------------------------------------------------
\subsection{数学関数}
%---------------------------------------------------------------------
\begin{table}[hbtp]
 \caption{gunplotの組み込み数学関数．\tw{x}は実数，\tw{z}は複素数，\tw{rz}は実数
 もしくは複素数の実部を表す．文献~\cite{GNUPLOT_Reference}を
参考に作成．}
\label{table:gunplot_include_math_func}
 \begin{center}
  \begin{tabular}{llp{5mm}ll}
   \cline{1-2} \cline{4-5}
   関数 & 動作 & & 関数 & 動作 \\
   \cline{1-2} \cline{4-5}
   \tw{abs(z)} & 絶対値 $|z|$ & & \tw{ibeta(p,q,rz)} & 不完全ベータ関数 \\
   \tw{acos(z)} & $\arccos(z)$ & & \tw{igamma(a,rz)} & 不完全ガンマ関数 \\
   \tw{acosh(z)} & $\mathrm{arccosh}(z)$ & & \tw{imag(z)} & $z$の虚部 $\Im(z)$ \\
   \tw{asin(z)} & $\arcsin(z)$ & & \tw{int(rz)} & rz の整数部を求める関数 \\
   \tw{asinh(z)} & $\mathrm{arcshinh(z)}$ & & \tw{inverf(rz)} & erf(rz) の逆関数 \\
   \tw{atan(z)} & $\arctan(z)$ & & \tw{invnorm(rz)} & norm(rz) の逆関数 \\
   \tw{atan2(z1,z2)} & 逆正接関数($-\pi$〜$\pi$) & & \tw{lgamma(rz)} & 対数ガンマ関数 \\
   \tw{atanh(z)} & $\mathrm{arctanh}(z)$ & & \tw{log(z)} & $\log_e(z)$ \\
   \tw{besj0(x)} & 0次ベッセル関数 $J_0(x)$ & & \tw{log10(z)} & $\log_{10}(z)$ \\
   \tw{besj1(x)} & 1次ベッセル関数 $J_1(x)$ & & \tw{norm(rz)} & 正規分布関数の累積を求める関数 \\
   \tw{besy0(x)} & 0次ノイマン関数 $Y_0(x)$ & & \tw{rand(rz)} & 擬似乱数を発生させる関数 \\
   \tw{eesy1(x)} & 1次ノイマン関数 $Y_1(x)$ & & \tw{real(z)} & zの実部 $\Re(z)$ \\
   \tw{ceil(rz)} & $z$以上の最小の整数を求める関数 & & \tw{sgn(rz)} & $\Re(z)$の符号を求める関数 \\
   \tw{cos(z)} & $\cos(z)$ & & \tw{sin(z)} & $\sin(z)$ \\
   \tw{cosh(z)} & $\cosh(z)$ & & \tw{sinh(z)} & $\sinh(z)$ \\
   \tw{erf(rz)} & (正規化)誤差関数 $\mathrm{erf}(z)$ & & \tw{sqrt(z)} & $\sqrt{z}$ \\
   \tw{erfc(rz)} & $1-\mathrm{erf}(z)$を示す関数 & & \tw{tan(z)} & $\tan(z)$ \\
   \tw{exp(z)} & $e^z$ & & \tw{tanh(z)} & $\tanh(z)$ \\
   \tw{floor(rz)} & $z$以下の最大整数を求める関数 & &  \\
   \tw{gamma(rz)} & ガンマ関数 $\Gamma(z_r)$ & &  \\
   \cline{1-2} \cline{4-5}
  \end{tabular}
 \end{center}
\end{table}
%
\newpage
%---------------------------------------------------------------------
\subsection{コマンド}
%---------------------------------------------------------------------
\begin{table}[H]
 \caption{gunplotのコマンドの一覧．文献~\cite{GNUPLOT_Reference}から引用．}
\label{table:gunplot_commands}
 \begin{center}
  \begin{tabular}{ll}
   \hline
   コマンド & 動作 \\
   \hline\hline
   \tw{cd} & 作業ディレクトリを移動 \\
   \tw{call} & スクリプトファイル内の変数(\tw{\$n})に値を渡す \\
   \tw{clear} & 現在スクリーンに表示されている内容を全消去 \\
   \tw{exit} & GNUPLOT を終了 \\
   \tw{fit} & 最小二乗法によるデータの補間 \\
   \tw{help} & ヘルプビューアを軌道 \\
   \tw{if} & 条件分岐命令 \\
   \tw{load} & スクリプトファイルの読み込み \\
   \tw{pause} & GNUPLOT の動作を一時停止 \\
   \tw{plot} & グラフの描画 \\
   \tw{print} & 変数の内容などの表示 \\
   \tw{pwd} & 現在の作業ディレクトリ名を表示 \\
   \tw{quit} & GNUPLOT の終了 \\
   \tw{replot} & 前に実行した plot コマンドを再実行 \\
   \tw{reread} & \tw{load} コマンドで読み込んだスクリプトファイルの再読込 \\
   \tw{reset} & \tw{set} コマンドで設定したオプションをすべてデフォルトの値に戻す \\
   \tw{save} & ユーザ定義関数やグラフの数値，使用オプションをファイルに保存 \\
   \tw{set} & 各種オプションの設定 \\
   \tw{show} & 現在の設定内容の表示 \\
   \tw{shell} & シェルの起動 \\
   \tw{splot} & 3次元グラフの描画 \\
   \tw{test} & 使用可能な線種や点種などをすべて表示 \\
   \tw{update} & \tw{fit} コマンドで用いるパラメータファイルの更新 \\
   \hline
  \end{tabular}
 \end{center}
\end{table}
%
\newpage
%---------------------------------------------------------------------
\subsection{詳細設定}
%---------------------------------------------------------------------
gunplotでは設定のコマンド(\tw{set})に引き続き設定項目を記述すると，きめ細かな設
定が可能である．設定は\tw{set}コマンドを使い，現在の設定を見るためには，\tw{show
all}を使う．デフォルトの設定に戻すには，\tw{rest}コマンドをつかう．表
\ref{table:gunplot_set}に設定可能なものを示すが，詳細は\tw{help}コマンド，あるい
はwebを調べよ．
\begin{table}[H]
 \caption{gunplotのコマンドの一覧．文献~\cite{GNUPLOT_set}を参考に作成．}
 \label{table:gunplot_set}
 \begin{center}
  \begin{small}
   \begin{tabular}{|ll|ll|ll|}
    \hline
    \tw{angles} & 角度の単位 & 
    \tw{missing} & 欠けているデータ & 
    \tw{x2label} & 軸のラベル \\

    \tw{arrow} & 矢印 & 
    \tw{mouse} & マウス & 
    \tw{x2mtics} & 軸目盛りを月\\

    \tw{autoscale} & scaleの自動設定軸 & 
    \tw{multiplot} & 複数のグラフ描画 & 
    \tw{x2range} &  軸の最大値/最小値 \\

    \tw{bars} &  誤差棒の先 &
    \tw{mx2tics} & 軸の小目盛 &
    \tw{x2tics} &  軸の大目盛 \\

    \tw{bmargin} & 下の余白 &
    \tw{mxtics} &  軸の小目盛 &
    \tw{x2zeroaxis} & ゼロ軸の表示/非表示 \\

    \tw{border} & 境界(軸，枠) &
    \tw{my2tics} &  軸の小目盛 &
    \tw{xdata} & データ型が日時 \\

    \tw{boxwidth} & 箱の幅 &
    \tw{mytics} &  軸の小目盛 &
    \tw{xdtics} & 軸目盛りを曜日 \\

    \tw{cbdata} & &
    \tw{mztics} & 軸の小目盛 &
    \tw{xlabel} &  軸のラベル\\

    \tw{cbdtics} & &
    \tw{offsets} & 描画素領域 &
    \tw{xmtics} & 軸目盛りを月 \\

    \tw{cblabel} & &
    \tw{origin} & 原点の位置&
    \tw{xrange} & 軸の最大値/最小値 \\
    
    \tw{cbmtics} & &
    \tw{output} & ファイル/デバイス &
    \tw{xtics} & 軸の大目盛 \\

    \tw{cbrange} & &
    \tw{palette} & &
    \tw{xzeroaxis} & ゼロ軸の表示/非表示 \\

    \tw{cbtics} & &
    \tw{parametric} & 媒介変数の使用 &
    \tw{y2data} & データ型が日時\\

    \tw{clabel} & 等高線の凡例 &
    \tw{pm3d} & 3次元カラー &
    \tw{y2dtics} & 軸目盛りを曜日 \\

    \tw{clip} & 枠付近のデータ制御 &
    \tw{pointsize} &  記号の大きさ &
    \tw{y2label} &  軸のラベル\\

    \tw{cntrparam} &  等高線の制御 &
    \tw{polar} & 極座標表示 &
    \tw{y2mtics} & 軸目盛りを月\\

    \tw{colorbox} & & 
    \tw{print} & リダイレクト先 &
    \tw{y2range} & 軸の最大値/最小値 \\

    \tw{contour} & 等高線の表示 &
    \tw{rmargin} & 右の余白 &
    \tw{y2tics} &  軸の大目盛 \\

    \tw{datafile} & データファイル設定 &
    \tw{rrange} & 軸の最大値/最小値 &
    \tw{y2zeroaxis} & ゼロ軸の表示/非表示 \\

    \tw{date\_specifiers} & 日時のフォーマット &
    \tw{samples} & サンプル数 &
    \tw{ydata} & データ型が日時 \\
    
    \tw{decimalsign} & &
    \tw{size} & 図の大きさ &
    \tw{ydtics} & 軸目盛りを曜日 \\

    \tw{dgrid3d} & 3次元データを格子 &
    \tw{style} & プロットスタイル &
    \tw{ylabel} & 軸のラベル \\

    \tw{dummy} & 独立変数の変更 &
    \tw{surface} &  3次元表示の面 &
    \tw{ymtics} & 軸目盛りを月\\

    \tw{encoding} & 文字コード &
    \tw{term} & ターミナルの設定 &
    \tw{yrange} & 軸の最大値/最小値 \\

    \tw{fit} & フィッティング &
    \tw{terminal} & ターミナルの設定 &
    \tw{ytics} & 軸の大目盛 \\

    \tw{fontpath} & フォントのパス &
    \tw{tics} & 目盛の向き &
    \tw{yzeroaxis} & ゼロ軸の表示/非表示 \\

    \tw{format} &  軸の数字の書式 &
    \tw{ticscale} & 目盛の長さ &
    \tw{zdata} & データ型が日時 \\

    \tw{grid} &  格子を描く &
    \tw{ticslevel} & \tw{splot}の面間隔 &
    \tw{zdtics} & 軸目盛りを曜日 \\

    \tw{hidden3d} & 隠線処理 &
    \tw{time} & プロットの日時 &
    \tw{zero} & ゼロの敷居値 \\

    \tw{historysize} & &
    \tw{time\_specifiers} & 日時のフォーマット &
    \tw{zeroaxis} & ゼロ軸の表示/非表示 \\
    
    \tw{isosamples} & 3次元の線の数 &
    \tw{timefmt} & 日時のフォーマット &
    \tw{zlabel} & 軸のラベル \\
    
    \tw{key} & 凡例 &
    \tw{timestamp} & プロットの日時 &
    \tw{zmtics} & 軸目盛りを月\\
    
    \tw{label} & 任意のラベル &
    \tw{title} &  図のタイトル &
    \tw{zrange} & 軸の最大値/最小値 \\
    
    \tw{lmargin} & 左の余白 &
    \tw{tmargin} & 上の余白 &
    \tw{ztics} & 軸の大目盛 \\
    
    \tw{loadpath} & パス &
    \tw{trange} & 軸の最大値/最小値 &
    & \\
    
    \tw{locale} & ロケール設定 &
    \tw{urange} & 軸の最大値/最小値 &
    & \\
    
    \tw{log} & $\log$プロット &
    \tw{view} & 3次元表示の視点 &
    & \\
    
    \tw{logscale} & 対数軸 &
    \tw{vrange} & 軸の最大値/最小値 &
    & \\
    
    \tw{mapping} & 3次元の座標系 &
    \tw{x2data} & データ型が日時 &
    & \\
    
    \tw{margin} & 外側の余白 &
    \tw{x2dtics} & 軸目盛りを曜日 &
    & \\
    \hline
   \end{tabular}
  \end{small}
 \end{center}
\end{table}
%=====================================================================
%  参考文献
%=====================================================================
\bibliographystyle{junsrt}
\bibliography{reference}
%=====================================================================
	\end{document}
