Return to 参考:初等関数のグラフを描く

参考:gnuplot で初等関数のグラフを描く

べき関数

$y = x^{-2}, \ x^{-1}, \ x^2, \ x^3$ のグラフ例。

In [1]:
reset
# なめらかな曲線のために
set samples 200
# x軸 y軸を描く
set zeroaxis
# グリッド(格子)を描く
set grid
# 縦軸横軸の目盛を 1 刻みで
set xtics 1
set ytics 1
# 凡例の横の線の長さ
set key sample 1
In [2]:
plot [-5:5][-5:5] x**(-2) lw 2 title "x^{-2}", \
                  x**(-1) lw 2 title "x^{-1}", \
                  x**2 lw 2 title "x^2", \
                  x**3 lw 2 title "x^3"

$\displaystyle y = \sqrt{x}, \ \frac{1}{\sqrt{x}}$ のグラフ例。

In [3]:
plot [0:5][0:5] sqrt(x) lw 2, 1/sqrt(x) lw 2

… ということで,関数の分母がゼロになるような場合でも,gnuplot は文句を言わずにグラフを描いてくれる。

指数関数

$y = e^{-x}, \ e^x$ のグラフ例。

In [4]:
plot [-5:5][-0.1:5] exp(-x) lw 2 title "e^{-x}", \
                    exp(x) lw 2 title "e^x"

三角関数

$ y = \sin x, \ \cos x, \ \tan x $ のグラフ例。

In [5]:
# 横軸 π/4 ごとに目盛
set xtics pi/2
# 目盛ラベルのフォーマット設定
set format x '%3.1P π'

plot [-2*pi:2*pi][-3:3] sin(x) lw 2 title "sin x", \
                        cos(x) lw 2 title "cos x", \
                        tan(x) lw 2 title "tan x"

set xtics auto
unset format x

逆三角関数

$y = \sin^{-1} x = \arcsin x =$ asin(x) の定義域は $-1 \leq x \leq 1$
$y = \cos^{-1} x = \arccos x =$ acos(x) の定義域は $-1 \leq x \leq 1$
$y = \tan^{-1} x = \arctan x =$ atan(x) の定義域は $-\infty < x < \infty$

In [6]:
set xtics 0.5
set ytics pi/4
# 目盛ラベルのフォーマット設定
set format y '%4.2P π'

plot [-1:1] asin(x) lw 2 title "sin^{-1} x", \
            acos(x) lw 2 title "cos^{-1} x"

In [7]:
set xtics 2
set ytics pi/4
# 目盛ラベルのフォーマット設定
set format y '%4.2P π'
set key top left

plot [-10:10] atan(x) lw 2 title "tan^{-1} x"

双曲線関数

$y = \sinh x, \ \cosh x, \ \tanh x$ のグラフ例。

In [8]:
set xtics 1
unset format y
set ytics 10

plot [-4:4] sinh(x) lw 2 title "sinh x", \
            cosh(x) lw 2 title "cosh x"

In [9]:
set ytics 0.2

plot [-5:5] tanh(x) lw 2 title "tanh x"

逆双曲線関数

$ y = \sinh^{-1} x = \mbox{arsinh}\ x = $ asinh(x) $= \log\left(x+\sqrt{x^2+1}\right)$
$ y = \cosh^{-1} x = \mbox{arcosh}\ x = $ acosh(x) $= \log\left(x+\sqrt{x^2-1}\right)$
$ y = \tanh^{-1} x = \mbox{artanh}\ x = $ atanh(x)
$\displaystyle = \frac{1}{2} \log\left(\frac{1+x}{1-x}\right)$

In [10]:
set ytics 1
set key top left

plot [-5:5] asinh(x) lw 2 title "sinh^{-1} x"

In [11]:
plot[1:5] acosh(x) lw 2 title "cosh^{-1} x"

In [12]:
set xtics auto
plot [0:1] atanh(x) lw 2 title "tanh^{-1} x"