矢崎成俊(宮崎大学)
第
1
章
Gnuplot
の基本操作
gnuplot(グニュプロット)のホームページ(http://www.gnuplot.info/) から,最新版のWindows用のgnuplot(2011年6月22日現在,バージョ ン4.4.3のgp443win32.zipが最新のファイル)をダウンロードして,それ を展開する.そうすると,gnuplotフォルダが生成され,その中には,binary, contrib, demo, docs, license
の 5 つ の フ ォ ル ダ と ,BUGS, ChangeLog, Copyright, INSTALL, NEWS, README, README.1ST, README.Windows, VERSION などのファイルが含 まれている. 注 ファイルの拡張子を見えるようにするために,以下の(1)∼(4)をお こなっておく. (1) [スタート]→[コントロールパネル] に入って,右上の表示方法を[小 さいアイコン]にする. (2) [フォルダーオプション]をクリックする. (3) [表示]タブをクリックする. (4)下から3行目あたりの[登録されている拡張子は表示しない]のチェッ クをはずす. binaryフォルダの中の
wgnuplot.exe
がWindows用のgnuplotの実行ファイルである.(他にも,gnuplot.exe
など,hogehoge.exeという実行ファイルがいくつかあるが,それらの用途 については,README.Windowsで説明されている.) さて,なんだかんだと,上のようにWindows OS上にどうにかインス トールできたとして,そこから話をはじめよう.(UnixやMacを使ってい る人は問題ないと考えている.)
1.1
Gnuplot
の起動と終了
wgnuplot.exeをダブルクリックすれば(あるいはEnterキーを押せば), G N U P L O T Version 4.4 patchlevel 3 last modified March 2011 System: MS-Windows 32 bitCopyright (C) 1986-1993, 1998, 2004, 2007-2010 Thomas Williams, Colin Kelley and many others
gnuplot home: http://www.gnuplot.info faq, bugs, etc: type "help seeking-assistance" immediate help: type "help"
plot window: hit ’h’
Terminal type set to ’wxt’ gnuplot> _ という表示とともにgnuplotが起動する. 一番最後の, gnuplot> _ の「 _ 」部分(カーソル)は点滅しており,ここにいろいろな命令(コマ ンド)を入力していく.例えば,
gnuplot> exit あるいは, gnuplot> quit あるいは, gnuplot> q と入力したら,gnuplotは終了する.
1.2
作業用フォルダを作る
例えば,あなた(ユーザー名をyouとしよう)のマイドキュメントに,例 えば,gp-filesなるフォルダを作ると, ▶ コンピュータ ▶ ローカルディスク(C:) ▶ ユーザ ▶ you ▶ マイドキュメント▶ gp-files という階層構造が表示されるが,実は,C:Y=UsersY=youY=DocumentsY=gp-files
という場所のことである.ともあれ,マイドキュメントでなくてもよいの で,どこかに,作業用のフォルダを作っておく.注意点は,フォルダ名に日 本語が入らないようにしておくこと.例えば,
C:Y=UsersY=あなたY=DocumentsY=gp-files
C:Y=UsersY=youY=DocumentsY=ぐにゅぷろっと
などというフォルダ名は避ける.基本的に,英語やローマ字などの「半角英 数字」を使うようにする. そうしたら,gnuplotを起動して,以下のように,上で作った作業用フォ ルダにディレクトリを変更する(change directory).
gnuplot> cd ’C:Y=UsersY=shigeY=DocumentsY=gp-files’
あるいは,gnuplot起動画面の上にある左から4番目のボタンChDirをク リックして,C:Y=UsersY=youY=DocumentsY=gp-filesをコピーペースト(あ るいは入力)してもよい.上のように入力したことと同じ結果になる.
本当に移動したかをチェックするには,現在作業している場所(current working directory)を以下のように表示する(print working directory).
gnuplot> pwd
そして,
C:Y=UsersY=youY=DocumentsY=gp-files gnuplot> となればOKである. さて,以上で準備が整った.
1.3
Gnuplot
の基本操作
◎—関数を与えてグラフを描くコマンド(plot) 例えば,y = sin xのグラフを描きたい場合,gnuplot> plot sin(x)
xの範囲(横軸)が[−10, 10]で,yの範囲(縦軸)が[−1, 1]となった. これは自動的に見やすい形に設定される.自分で範囲を設定したい場合,例 えば,xの範囲を[−2π, 2π], yの範囲を[−2, 2]としたい場合,
gnuplot> plot [-2*pi:2*pi] [-2:2] sin(x)
とする.さらに,
gnuplot> plot [0:4*pi] sin(x)
とすると,xの範囲が[0, 4π]に設定され,yの範囲は自動設定となる. また,複数の関数を同時に描画することも可能である.
gnuplot> plot [0:2*pi] [0:1.5] sin(x), x, x-x**3/3!, Y= > x-x**3/3!+x**5/5!
◎—過去に入力したコマンドの再利用 同 じ よ う な コ マ ン ド を 何 度 も 打 鍵 す る の は 面 倒 で あ る .そ こ で , Ctrl + P を押せば,1回前に入力したコマンドが表示される(previous). そのままCtrlキーを押しながら, Pを押すとPを押した回数分だけ前に 入力したコマンドが表示される.Ctrl + Nを押せば(next),1回次に進 み,そのまま Ctrlキーを押しながら, Nを押すとNを押した回数分だけ 次に入力したコマンドが表示される. 例えば,
gnuplot> plot sin(x)
と入力した後に,cos xを描画したいときは,Ctrl + P を押して,←で カーソルを動かして,DelやBack space キーを使ってsinの部分のみを 消して,cosを打ち直せばよい.
◎—データファイルの読み込み(plot ... using ... with)
1 1 1 2 4 8 3 9 27 4 16 64 5 25 125 これに対して,
gnuplot> plot ’data.dat’ using 1:2 with lines
とする.意味はdata.datの1行目をx座標(横軸),2行目をy座標(縦 軸)と考えて,それらを線で結ぶ,ということである.下図が表示されるで あろう. さらに,
gnuplot> plot ’data.dat’ using 1:2 with linespoint, x*x
もしusing 3:1と書いたらdata.datの3行目をx座標,1行目をy座 標と考えることとなる.したがって,
gnuplot> plot ’data.dat’ using 3:1 w lp, x**(1.0/3.0)
と書いたら(w lpはwith linespointの略),下図のようなマーカー付き 折れ線と曲線x1/3が両方描かれる.
using x:yを省略したらデータファイルの1行目をx座標データ,2行 目をy座標データとして読み込むことになっている.
◎—世界地図データファイルの読み込み
gnuplotY=demoの中にあるworld.datを現在の作業フォルダgp-files
にコピーして,その中に書いてある2次元座標のデータを
gnuplot> plot ’world.dat’
のようにプロットすると,次のようになる.
このデータを
gnuplot> plot ’world.dat’ w l
となり,
gnuplot> plot ’world.dat’ w lp
とすれば,
のような各座標にマークした折れ線となる.また,中身を塗りつぶして,
とするには,
gnuplot> plot ’world.dat’ w filledcurve
◎—単項・二項演算子(+, -, *, /, **, %, !)
単項・二項演算子も素直に普通のものが使える.加減乗除は+, -, *, /
で,冪乗は**,剰余(mod)は%である.また,階乗は!である.例えば,
gnuplot> plot [0.02:0.2] cos(exp(x**x)/x)/x
とすると,xの範囲が[0.02, 0.2]で,関数y = cos exp(xx) x x のグラフが描か れる. ギザギザしているのは,使っているサンプル点が少ないからである.実際,
gnuplot> plot [0.02:0.2] cos(exp(x**x)/x)/x w lp
となることからもわかる.指定しない限りサンプル点は100個となってい る.だから,振動の激しいグラフはギザギザになる.サンプル点を10000
個にしたかったら,
gnuplot> set samples 10000
とする.そうして,
gnuplot> plot [0.02:0.2] cos(exp(x**x)/x)/x w l
として再度描画すると,滑らかな曲線
◎— Gnuplotを電卓として使う(print) 上で述べた二項演算子を使って,電卓として使うこともできる.例えば, 123÷ 5は, gnuplot> print 123.0/5.0 と入力する.すると,次の行に gnuplot> print 24.6 と表示される. ここでもし, gnuplot> print 123/5 としたら, gnuplot> print 24 と整数部分のみ表示されることに注意されたい.また,階乗!は実数型で返 される.例えば, gnuplot> print 10! とすると, gnuplot> 3628800.0 となる.
◎—画像ファイルに出力する(set term, set output)
次の3つの入力を順次行なう.
gnuplot> set terminal jpeg
あるいは,
gnuplot> set term jpeg
とする.他にも非常に多くのグラフィック装置をサポートしている.
(2)次に,出力ファイル名を入力する.例えば,
gnuplot> set output ’world.jpeg’
とする.
(3)最後に,描画する.
gnuplot> plot ’world.dat’ w filledcurve
何も表示されないが,gp-filesの中に,world.jpegファイルが生成され ている.それをクリックしたら適当なビューアーで画像をみることができ るが,使用中で開けないこともある(ファイルサイズが0KBのときはそう である).そのときは,
gnuplot> set output ’dummy’
な ど と し て ,ダ ミ ー の 画 像 フ ァ イ ル を 生 成 す れ ば よ い .そ う す る と , world.jpeg のファイルサイズが75KBのように表示され,閲覧可能に なる.dummyを作る代わりに,gnuplotを終了してもよい. Windowsの描画モードに戻るには,
gnuplot> set term windows
◎—ヘルプ機能
いままで登場したコマンドはほんの一部である.多くの具体例は,gnuplot homepageのdemoを見たり,ヘルプ機能を使うとよい.Windows 7で.hlp
ファイルを閲覧してヘルプ機能を使うには,WinHlp32.exeというアプリ ケーションをインストールする必要がある.
インターネットで,Microsoft(R) Download Centerの
Windows 7 用Windows Helpプログラム(WinHlp32.exe)
のページにいって,手順に従いインストールする.上のページは,インター ネットの検索機能を使って探す. http://www.microsoft.com/downloads/ja-jp/... ではじまるURLのはずである. 晴れて,ヘルプ機能が使えるようになったら,gnuplotのHelpボタンを クリックするか, gnuplot> help あるいは, gnuplot> ? と入力する. 具体的に,withの種類を知りたいときは,
gnuplot> help with
第
2
章
初等関数
いろいろな初等関数を描画してみよう.その前に,ファイルの読み込み操 作について説明する.これを知っているのと知らないのとでは雲泥の差で ある.2.1
ファイルの読み込み
(load)
例えば,プログラム Aのようなコマンドを入力したとしよう.説明のた めに行番号を付した.#以下は読み込まれないので,必要に応じてコメント を書くとよい.今は説明のためにコメントを書いてある.わかりにくそう な点のみ説明する. reset 1 行 目 の リ セ ッ ト 命 令 は ,そ の 通 り に 今 ま で に 入 力 し た も の す べ て を ご 破 算 に す る と い う 意 味 で あ る .た だ し ,set term と set output な ど の い く つ か の コ マ ン ド は ご 破 算 に な ら な い .( と り あ え ず こ の 2 つ は ,ご 破 算 に な ら な い こ と を 知 っ て お け ば よ い .)set term windows color enhanced としておくと,x^2がx2 に,x_2
がx2になる.上で述べたようにresetではリセットされないので,x^2や
x_2をそのまま出力したい場合には,noenhancedとする.
set key 8行目の命令は,座標(1.1a, a)にグラフの凡例の左側(l, left)
cだったら中央(center)である.また,unset keyで,凡例を出力しない 命令となる.
プログラム A
1:gnuplot> reset #リセット(ご破算)
2:gnuplot> set term windows color enhanced 3:gnuplot> set size square #描画領域を正方形にする
4:gnuplot> set samples 10000 5:gnuplot> a = 1.5
6:gnuplot> set xrange [-a:a] # (−a ≤ x ≤ a) 7:gnuplot> set yrange [-a:a] # (−a ≤ y ≤ a) 8:gnuplot> set key at a*1.1, a l
9:gnuplot> set arrow 1 from -a, 0 to a, 0 head 10:gnuplot> set arrow 2 from 0, -a to 0, a head 11:gnuplot> f(x, n) = x**n # f (x, n) = xn
12:gnuplot> set title ’polynomial functions’ #タイトル
13:gnuplot> plot f(x, 1) t ’x’, f(x, 2) t ’x^2’, Y= 14:> f(x, 3) t ’x^3’, f(x, 4) t ’x^4’, Y=
15:> f(x, 5) t ’x^5’, f(x, 6) t ’x^6’, Y= 16:> f(x, 7) t ’x^7’, f(x, 8) t ’x^8’ 17:gnuplot> pause -1
18:gnuplot> set title ’odd degree functions’ 19:gnuplot> plot f(x, 1) t ’x’, f(x, 3) t ’x^3’, Y= 20:> f(x, 5) t ’x^5’, f(x, 7) t ’x^7’
set arrow 9行目の矢印命令は,矢印の整理番号1で,座標(−a, 0)か ら(0, a)まで矢印を鏃(head)付きで描くということである.10行目の矢 印命令は,整理番号2である.unset arrow 1で,整理番号1の矢印命令 を取り消すことができる.unset arrow で,すべての矢印命令の取り消し となる.
行しているが,それぞれ一つの描画命令である.plot f(x, 1) t ’x’で,
x1を凡例タイトルxで描くということである.もし,tを省略したら,凡
例タイトルはf(x, 1)となる.他も同様である.
pause -1 17行目は,一時停止命令である.下図が表示されるので,
OKをクリックすれば次に進む.
また,pause 15とすれば15秒停止し,pause mouseとすればマウスをク リックするまでとなるなど,他のオプションもある.
こうして,プログラム Aを実行すると,以下の2画面が表示されるであ ろう.
◎— aの値を変えたいとき プログラム Aにおいて,5行目のaの値を変えると,aに依存した部分 のグラフの描画範囲や矢印などが変わる.そのため,6行目以降をすべて再 入力する必要がでてくる.これでは,あまりに非効率であるので,プログラ ムAを,例えば,ファイル名programA.gnuのファイルに書き込んでおき, それを読み込むという方法がある.読み込み命令は,以下のようにする.
gnuplot> load ’programA.gnu’
reset
set term windows color enhanced set size square
set samples 10000 a = 1.5
set xrange [-a:a] set yrange [-a:a] set key at a*1.1, a l
set arrow 1 from -a, 0 to a, 0 head set arrow 2 from 0, -a to 0, a head f(x, n) = x**n
set title ’polynomial functions’ plot f(x, 1) t ’x’, f(x, 2) t ’x^2’, Y= f(x, 3) t ’x^3’, f(x, 4) t ’x^4’, Y= f(x, 5) t ’x^5’, f(x, 6) t ’x^6’, Y= f(x, 7) t ’x^7’, f(x, 8) t ’x^8’ pause -1 #
set title ’odd degree functions’ plot f(x, 1) t ’x’, f(x, 3) t ’x^3’, Y= f(x, 5) t ’x^5’, f(x, 7) t ’x^7’
2.2
多項式関数
多項式関数(polynomial functions)の描画ファイルなので,ファイル名 をpoly.gnuとした.以下,poly.gnu (1)∼(3)に分割して解説する.poly.gnu (1)を簡単に解説すると,set grid は,格子を描く命令.
set arrowのところのltはlinetype(線の種類),lwはlinewidth(線 の太さ)の略である.また,鏃を少し凝っている.
f(x, n) = x**n以降は,プログラム A (programA.gnu)の多項式関数 の部分と奇数次(odd degree)の多項式関数の部分に,偶数次(even degree) の多項式関数の部分が加えてあるだけである.(pause -1をpause mouse
に変えてみた.)奇数次の多項式関数は奇関数だから,原点対称なグラフ, 偶数次の多項式関数は偶関数だから,y軸について対称なグラフである.
poly.gnu (1)
reset
set term windows color enhanced set size square
set samples 10000 a = 1.5
set xrange [-a:a] set yrange [-a:a] set grid
set key at a*1.1, a l
set arrow 1 from -a, 0 to a, 0 head back filled lt -1 lw 2 set arrow 2 from 0, -a to 0, a head back filled lt -1 lw 2 #
f(x, n) = x**n #
set title ’polynomial functions’
plot f(x, 1) t ’x’, f(x, 2) t ’x^2’, f(x, 3) t ’x^3’, Y= f(x, 4) t ’x^4’, f(x, 5) t ’x^5’, f(x, 6) t ’x^6’, Y= f(x, 7) t ’x^7’, f(x, 8) t ’x^8’
pause mouse #
set title ’odd degree functions’ plot f(x, 1) t ’x’, f(x, 3) t ’x^3’, Y= f(x, 5) t ’x^5’, f(x, 7) t ’x^7’ pause mouse
#
set title ’even degree functions’ plot f(x, 2) t ’x^2’, f(x, 4) t ’x^4’, Y= f(x, 6) t ’x^6’, f(x, 8) t ’x^8’ pause mouse (poly.gnu (2)に続く) ここまでのプログラムで下図を得るだろう.
poly.gnu (1)からの続きで,poly.gnu (2)では,1次関数から4次関数 までを描いている.1次関数は直線であり,2次関数は放物線(谷1つ),3 次関数は山1つと谷1つ,4次関数は山1つと谷2つである. poly.gnu (2) unset key
set title ’degree 1: y=x’ plot f(x, 1)
pause mouse #
set title ’degree 2: y=x^2’ plot f(x, 2)
pause mouse #
set title ’degree 3: y=x(x^2-1)’ plot x*(x**2-1)
pause mouse #
set title ’degree 4: y=5x^2(x^2-1)’ plot 5*x**2*(x**2-1)
pause mouse
(poly.gnu (3)に続く)
poly.gnu (2)からの続きで,poly.gnu (3)では,形が典型的な5次関数 と6次関数を描いている.5次関数は山2つと谷2つ,6次関数は山2つと 谷3つである.
poly.gnu (3)
set title ’degree 5: y=10x(x^2-1)(x^2-0.25)’ plot 10*x*(x**2-1)*(x**2-0.25)
pause mouse #
set title ’degree 6: y=15x^2(x^2-1)(x^2-0.25)’ plot 15*x**2*(x**2-1)*(x**2-0.25)
多項式関数は次数が増えるごとに,山か谷の数が一つずつ増えることが特 徴である.
2.3
三角関数
三角関数(trigonometric functions)の描画ファイルなので,ファイル名 をtri.gnuとした.以下,tri.gnu (1)∼(4)に分割して解説する.
unset boder 枠(boder)の取り消しである.デフォルト(あらかじめ 自動的に設定されている標準状態)では,set boderになっている.
set xtics -a,pi/2,a x軸の刻みを-aからaまで,π
2 ごとに書く. set ytics -floor(a),1,floor(a) y 軸 の 刻 み を-floor(a) か ら
floor(a) ま で ,1 ご と に 書 く .こ こ で ,floor(a) は ,床 関 数(floor function)で,ガウスの記号[a]と同じ意味である.つまり,
[a] = aを超えない最大の整数 の意味である.
unset key 凡例の取り消しである.一般に,unset xxxは,xxxの取 り消し命令であり,次に,set xxxが登場するまでこの命令は有効である.
reset
set term windows color enhanced set size square
set samples 10000 a = 2*pi
unset border set xrange [-a:a] set yrange [-a:a] set key at a, a l set xtics -a,pi/2,a
set ytics -floor(a),1,floor(a) set grid
set arrow 1 from -a, 0 to a, 0 head back filled lt -1 lw 2 set arrow 2 from 0, -a to 0, a head back filled lt -1 lw 2 #
unset key
set title ’y=sin x’ plot sin(x)
pause mouse #
set title ’y=cos x’ plot cos(x)
pause mouse
(tri.gnu (2)に続く)
tri.gnu (2)
set title ’y=tan x’ plot tan(x)
pause mouse #
set title ’trigonometric functions’ set key at a, a r
plot sin(x), cos(x), tan(x) pause mouse
(tri.gnu (3)に続く)
set title ’scaling: sin x vs. sin 2x’ plot sin(x), sin(2*x)
pause mouse #
set title ’scaling: sin x, 2sin x, 3sin x, 4sin x’ plot sin(x), 2*sin(x), 3*sin(x), 4*sin(x)
pause mouse #
set title ’scaling: sin x, (sin x)/2, sin(x/2)’ plot sin(x), sin(x)/2, sin(x/2)
pause mouse #
set title ’scaling: sin x, (sin 2x)/2, 2sin(x/2)’ plot sin(x), sin(2*x)/2, 2*sin(x/2)
pause mouse (tri.gnu (4)に続く) ここまでで,下図を得る. 以下,x方向とy方向にいろいろに縮尺を変えたsinの図を描いた.じっ くり吟味してほしい.
set title ’sin(1/x)’ plot sin(1/x) 最後に,この図は,x = 0では定義されない関数の図である.t = 1 x とお けば,sin1 x = sin tであり,xが原点に近づくと,tは無限遠方に飛んでい くから,
2.4
指数関数
指数関数(exponential functions)の描画ファイルなので,ファイル名を exp.gnuとした.もはや解説は必要ないだろう.実行してみよ.exp.gnu
reset
set term windows color enhanced set size square
set samples 10000 a = 6
b = -1 c = b + 2 * a unset border set xrange [-a:a] set yrange [b:c] set xtics -a,1,a set ytics b,1,c set grid
set arrow 1 from -a, 0 to a, 0 head back filled lt -1 lw 2 set arrow 2 from 0, b to 0, c head back filled lt -1 lw 2 #
unset key
set title ’y=e^x’ plot exp(x) pause mouse #
set title ’y=e^{-x}’ plot exp(-x)
pause mouse #
set key at a, c l
set title ’y=e^x and y=e^{-x}’ plot exp(x), exp(-x)
pause mouse #
set title ’y=0.5^x, 0.6^x, 0.7^x, 0.8^x, 0.9^x, 1^x, 1.1^x’ plot 0.5**x, 0.6**x, 0.7**x, 0.8**x, 0.9**x, 1**x, 1.1**x pause mouse
#
set title ’y=1.1^x, 1.2^x, 1.3^x, 1.4^x, 1.5^x, 2^x, e^x’ plot 1.1**x, 1.2**x, 1.3**x, 1.4**x, 1.5**x, 2**x, exp(x) pause mouse
2.5
対数関数
対数関数(logarithmic functions)の描画ファイルなので,ファイル名を log.gnuとした.log.gnu (1), (2)に分割して表示する. log.gnu (1) resetset term windows color enhanced set size square
set samples 10000 a = 6
unset border set xrange [-a:a] set yrange [-a:a] set xtics -a,1,a set ytics -a,1,a set grid
set arrow 1 from -a, 0 to a, 0 head back filled lt -1 lw 2 set arrow 2 from 0, -a to 0, a head back filled lt -1 lw 2 #
unset key
set title ’y=e^x’ plot exp(x) pause mouse #
set title ’y=log x=log_e x’ plot log(x)
pause mouse #
set key at a, a l
set title ’y=e^x, y=x, y=log x’
plot exp(x) t ’e^x’, x, log(x) t ’log x’ pause mouse
#
set key at a, a l
set title ’y=2^x, y=x, y=log_2 x’
plot 2**x t ’2^x’, x, log(x)/log(2) t ’log_2 x’ pause mouse
set key at a, a l
set title ’y=0.5^x, y=x, y=log_{0.5} x’
plot 0.5**x t ’0.5^x’, x, log(x)/log(0.5) t ’log_{0.5} x’ pause mouse
#
set key at a, a l set title Y=
’y=log_{0.5} x, y=log_{0.9} x, y=log_{1.1} x, y=log_2 x’ plot log(x)/log(0.5) t ’log_{0.5} x’, Y=
log(x)/log(0.9) t ’log_{0.9} x’, Y= log(x)/log(1.1) t ’log_{1.1} x’, Y= log(x)/log(2.0) t ’log_2 x’ pause mouse 最後のplotによるいろいろな底に対する対数関数の図は以下のように なる.
2.6
重要な極限
1
lim x→0 sin x x = 1であることを示すのに, sin x < x < tan x ( 0 < x <pi 2 )という不等式が鍵となる.この不等式の状況をグラフで見てみよう.以下 のようなプログラムを書けばよい.(set keyを少し変えてみた.)
limit1.gnu
reset
set term windows color enhanced set size square
set samples 10000 a = pi/2
unset border set xrange [0:a] set yrange [0:1] set xtics 0,0.2,a set ytics 0,0.2,1 set grid
set arrow 1 from 0, 0 to a, 0 head back filled lt -1 lw 2 set arrow 2 from 0, 0 to 0, 1 head back filled lt -1 lw 2 set key left box
#
set title ’sin x < x < tan x’ plot sin(x), x, tan(x)
2.7
重要な極限
2
自然対数 の底e は,e = lim n→∞ ( 1 + 1 n )n と定義さ れる.こ れより , lim x→∞ ( 1 + 1 x )x = eが得られることを以下の手順で示そう. (1) x > 1として,xの整数部分をn,小数部分をαとおいて,x = n + α と分解すると,n = [x],かつ0≤ α < 1である.よって,[x]≤ x < [x] + 1, すなわち,n≤ x < n + 1が成り立つ. 注 gnuplotで確認しよう.ファイルを作るまでもない.gnuplot> reset; set term windows color enhanced gnuplot> set samples 10000; set key left nobox gnuplot> plot [1:10][1:10] floor(x), x, floor(x)+1
とすれば,下図を得る. (2) n≤ x < n + 1より, 1 n + 1 < 1 x ≤ 1 n が成り立つ.よって, 1 + 1 n + 1 < 1 + 1 x≤ 1 + 1 n
である.辺々をそれぞれn≤ x < n + 1乗すれば, ( 1 + 1 n + 1 )n < ( 1 + 1 x )x < ( 1 + 1 n )n+1 を得る.すなわち, f (x) = ( 1 + 1 [x] + 1 )[x] = ( 1 + 1 n + 1 )n g(x) = ( 1 + 1 x )x h(x) = ( 1 + 1 [x] )[x]+1 = ( 1 + 1 n )n+1 とおけば,f (x) < g(x) < h(x)が示された. (3) lim n→+∞ ( 1 + 1 n )n = eより, lim n→+∞ ( 1 + 1 n + 1 )n+1 = eである. よって,n→ +∞のとき, ( 1 + 1 n + 1 )n = ( 1 + 1 n + 1 )n+1( 1 + 1 n + 1 )−1 → e 1 + 0 = e が成り立つので,極限 lim x→+∞f (x) = eを得る. (4) n→ +∞のとき, ( 1 + 1 n )n+1 = ( 1 + 1 n )n( 1 + 1 n ) → e(1 + 0) = e が成り立つので,極限 lim x→+∞h(x) = eを得る. (5)不等式 f (x) < g(x) = ( 1 + 1 x )x < h(x) および,(3), (4)の結果より,はさみうちの原理を用いて, lim x→+∞g(x) = lim x→+∞ ( 1 + 1 x )x = eを得る. 注 (3)∼(5)の挟み撃ちの原理を用いた証明をgnuplotで視覚化しよう. 次のようなファイルを書けばよいだろう.
reset; set term windows color enhanced set size square; set samples 10000 unset border set grid f(x) = ( 1.0 + 1.0 / ( floor(x) + 1.0 ) )**floor(x) g(x) = ( 1.0 + 1.0 / x )**x h(x) = ( 1.0 + 1.0 / floor(x) )**( floor(x) + 1.0 ) # a = 5 b = (a - 1) / 10.0 set xtics 1,b set ytics 1,0.5 set xrange [1:a] set yrange [1:5]
set arrow 1 from 1, exp(1.0) to a, exp(1.0) nohead set label 1 ’e’ at 1-b/4, exp(1.01) r
set title Y=
’lim(1+1/n)^n=e ---> lim(1+1/x)^x=e by squeeze theorem’ plot f(x) t ’( 1 + 1 / ( n + 1 ) )^n, n = [ x ]’, Y= g(x) t ’( 1 + 1 / x )^x’, Y= h(x) t ’( 1 + 1 / n )^{n + 1}, n = [ x ]’ pause mouse # a = 21; b = (a - 1) / 10.0 set xtics 1,b; set xrange [1:a]
set arrow 1 from 1, exp(1.0) to a, exp(1.01) nohead set label 1 ’e’ at 1-b/4, exp(1.01) r
replot; pause mouse #
a = 51; b = (a - 1) / 10.0 set xtics 1,b; set xrange [1:a]
set arrow 1 from 1, exp(1.0) to a, exp(1.01) nohead set label 1 ’e’ at 1-b/4, exp(1.01) r
replot
a = 21以下とa = 51以下は,a = 5以下のプログラムとほとんど変 わりがないので,aの値を変えたときに影響する部分だけを改めて書いた.
replotは再描画の意味である.set labelは,’e’というラベルの右側 (right)を整理番号1で,指定の場所(at)に書くというコマンドである.
注 lim n→+∞ 1 + 1 n = eであるのだから,極限x→+∞lim 1 + 1 x = e も成り立つことは当たり前に思うかもしれないが,自明ではない.実際,極 限 lim n→+∞g(n)と極限x→+∞lim g(x)が異なる例はすぐに作ることができる. 例えば, lim
n→+∞sin(πn) = 0だが,x→+∞lim sin(πx)は収束しない.
2.8
逆三角関数と双曲線関数
gnuplot で は ,逆 三 角 関 数 arcsin x, arccos x, arctan x は そ れ ぞ れ
asin(x), acos(x), atan(x)として用意されている.例えば,次のように 書く.
gnuplot> reset; set term windows color enhanced gnuplot> set samples 10000; set key left nobox gnuplot> set xzeroaxis; set yzeroaxis
gnuplot> plot [-1:1][-pi/2:pi] asin(x), acos(x) gnuplot> plot [-10:10][-pi/2:pi/2] atan(x)
双 曲 線 関 数 sinh x, cosh x, tanh x も そ れ ぞ れ sinh(x), cosh(x), tanh(x)として用意されている.