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

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

draw2d()

draw2d() は,関数の分母がゼロになったりしても文句を言わずにグラフを描く。

べき関数

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

In [1]:
draw2d(
  line_width = 2,
  color = 1, key = "x^{-2}",
  explicit(x**(-2), x, -5, 5),
  color = 2, key = "x^{-1}",
  explicit(x**(-1), x, -5, 5),
  color = 3, key = "x^{2}",
  explicit(x**2, x, -5, 5),
  color = 4, key = "x^{3}",
  explicit(x**3, x, -5, 5), 
  
  xrange = [-5, 5], yrange = [-10, 10], 
  xtics = 1, ytics = 2.5, xlabel = "x",
  xaxis = true, yaxis = true, grid = true
)$

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

In [2]:
draw2d(
  line_width = 2,
  color = 1, key = "x^{1/2}",
  explicit(sqrt(x), x, 0, 5),
  color = 2, key = "x^{-1/2}",
  explicit(1/sqrt(x), x, 0, 5),
  
  xrange = [0, 5], yrange = [0, 5], 
  xtics = 1, ytics = 1, xlabel = "x",
  xaxis = true, yaxis = true, grid = true
)$

指数関数

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

In [3]:
draw2d(
  line_width = 2,
  color = 1, key = "e^{-x}",
  explicit(exp(-x), x, -5, 5),
  color = 2, key = "e^{x}",
  explicit(exp(x), x, -5, 5),
  
  xrange = [-5, 5], yrange = [-1, 30], 
  xtics = 1, ytics = 5, xlabel = "x",
  xaxis = true, yaxis = true, grid = true, 
  user_preamble = "set key sample 1;"
)$

三角関数

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

In [4]:
draw2d(
  line_width = 2,
  color = 1, key = "sin x",
  explicit(sin(x), x, -2*%pi, 2*%pi+0.3),
  color = 2, key = "cos x",
  explicit(cos(x), x, -2*%pi, 2*%pi+0.3),
  color = 3, key = "tan x",
  explicit(tan(x), x, -2*%pi, 2*%pi+0.3),
  
  xrange = [-2*%pi, 2*%pi+0.3], yrange = [-5, 5], 
  xtics = {["-2π",-2*%pi],["-3π/2",-1.5*%pi],["-π",-%pi],["-π/2",-0.5*%pi], 
           ["0",0],
           ["2π", 2*%pi],["3π/2", 1.5*%pi],["π", %pi],["π/2", 0.5*%pi]}, 
  ytics = 1, 
  xaxis = true, yaxis = true, grid = true, xlabel = "x", 
  user_preamble = "set key sample 1;"
)$

逆三角関数

$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 [5]:
draw2d(
  line_width = 2,
  color = 1, key = "arcsin x",
  explicit(asin(x), x, -1, 1),
  color = 2, key = "arccos x",
  explicit(acos(x), x, -1, 1),
  
  xrange = [-1, 1], yrange = [-%pi/2, %pi], 
  xtics = 0.2, 
  ytics = {["-π/2",-%pi/2], ["-π/4",-%pi/4], ["0",0],
           ["π/4",%pi/4], ["π/2",%pi/2], ["3π/4", 3*%pi/4],  ["π", %pi]}, 
  xaxis = true, yaxis = true, grid = true, xlabel = "x"
)$

In [6]:
draw2d(
  line_width = 2,
  key = "arctan x",
  explicit(atan(x), x, -30, 30),
  
  xrange = [-30, 30], yrange = [-%pi/2, %pi/2], 
  xtics = 10, 
  ytics = {["-π/2",-%pi/2], ["-π/4",-%pi/4], ["0", 0],
           ["π/2", %pi/2],  ["π/4", %pi/4]}, 
  xaxis = true, yaxis = true, grid = true, xlabel = "x",
  user_preamble = "set key top left;"
)$

双曲線関数

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

In [7]:
draw2d(
  line_width = 2,
  color = 1, key = "sinh x",
  explicit(sinh(x), x, -5, 5),
  color = 2, key = "cosh x",
  explicit(cosh(x), x, -5, 5),
  
  xrange = [-5, 5], yrange = [-50, 50], 
  xtics = 1, ytics = 20, xlabel = "x",
  xaxis = true, yaxis = true, grid = true, 
  user_preamble = "set key bottom right;"
)$

In [8]:
draw2d(
  line_width = 2,
  key = "tanh x",
  explicit(tanh(x), x, -5, 5),
  
  xrange = [-5, 5], yrange = [-1, 1], 
  xtics = 1, ytics = 0.2, xlabel = "x",
  xaxis = true, yaxis = true, grid = true, 
  user_preamble = "set key bottom right;"
)$

逆双曲線関数

$ y = \sinh^{-1} x = \mbox{arsinh}\ x = $ asinh(x) の定義域は $ -\infty < x < \infty$

$ y = \cosh^{-1} x = \mbox{arcosh}\ x = $ acosh(x) の定義域は $ 1 \leq x < \infty$

$ y = \tanh^{-1} x = \mbox{artanh}\ x = $ atanh(x) の定義域は $ -1 < x < 1$

In [9]:
draw2d(
  line_width = 2,
  color = 1, key = "sinh^{-1} x", 
  explicit(asinh(x), x, -20, 20),
  color = 2, key = "cosh^{-1} x", 
  explicit(acosh(x), x, 1, 20),
  
  xrange = [-20, 20], yrange = [-4, 4], 
  xtics = 5, ytics = 1, 
  xaxis = true, yaxis = true, grid = true, 
  user_preamble = "set key top left;"
)$

In [10]:
draw2d(
  line_width = 2,
  key = "tanh^{-1} x",
  explicit(atanh(x), x, -0.99999, 0.99999),
  
  xrange = [-1.05, 1.05], yrange = [-6, 6], 
  xtics = 0.25, ytics = 2, xlabel = "x",
  xaxis = true, yaxis = true, grid = true, 
  user_preamble = "set key top left;"
)$

plot2d()

plot2d() は,関数の分母がゼロになったりすると文句を言うが,ちゃんとグラフを描いてくれる。

べき関数

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

In [11]:
plot2d(
  [x**(-2), x**(-1), x**2, x**3], [x, -5, 5], 
  [style, [lines, 2], [lines, 2], [lines, 2], [lines, 2]], 
  [legend, "x^{-2}", "x^{-1}", "x^2", "x^3"],
  
  [y, -10, 10], grid2d, [xtics, 1], [ytics, 2.5], 
  [gnuplot_preamble, "set key sample 1"]
)$
plot2d: expression evaluates to non-numeric value somewhere in plotting range.
plot2d: expression evaluates to non-numeric value somewhere in plotting range.

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

In [12]:
plot2d(
  [sqrt(x), 1/sqrt(x)], [x, 0, 5], 
  [style, [lines, 2], [lines, 2]], 
  [legend, "x^{1/2}", "x^{-1/2}"],
  
  [y, 0, 5], grid2d, [xtics, 1], [ytics, 1], 
  [gnuplot_preamble, "set key sample 1"]
)$
plot2d: expression evaluates to non-numeric value somewhere in plotting range.

指数関数

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

In [13]:
plot2d(
  [exp(-x), exp(x)], [x, -5, 5], 
  [style, [lines, 2], [lines, 2]], 
  [legend, "e^{-x}", "e^x"], 
  
  [y, -1, 30], grid2d, [xtics, 1], [ytics, 5]
)$

三角関数

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

In [14]:
plot2d(
  [sin(x), cos(x), tan(x)], [x, -2*%pi, 2*%pi+1], 
  [style, [lines, 2], [lines, 2], [lines, 2]], 
  [legend, "sin x", "cos x", "tan x"], 
  
  [y, -5, 5], grid2d, [xtics, %pi/2], [ytics, 1], 
  [gnuplot_preamble, "set format x '%3.1P π';set key sample 1;"]
)$

逆三角関数

$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 [15]:
plot2d(
  [asin(x), acos(x)], [x, -1, 1], 
  [style, [lines, 2], [lines, 2]], 
  [legend, "arcsin x", "arccos x"], 
  
  [y, -%pi/2, %pi], grid2d, [xtics, 0.2], [ytics, %pi/4], 
  [gnuplot_preamble, "set format y '%4.2P π';"]
)$

In [16]:
plot2d(
  atan(x), [x, -30, 30], 
  [style, [lines, 2]], 
  [legend, "arctan x"], [ylabel, ""],
  
  [y, -%pi/2, %pi/2], grid2d, [xtics, 10], [ytics, %pi/4], 
  [gnuplot_preamble, "set format y '%4.2P π';set key top left;"]
)$

双曲線関数

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

In [17]:
plot2d(
  [sinh(x), cosh(x)], [x, -5, 5], 
  [style, [lines, 2], [lines, 2]], 
  [legend, "sinh x", "cosh x"],
  
  [y, -50, 50], grid2d, [xtics, 1], [ytics, 20], 
  [gnuplot_preamble, "set key bottom right;"]
)$

In [18]:
plot2d(
  tanh(x), [x, -5, 5], 
  [style, [lines, 2]], [ylabel, ""], 
  [legend, "tanh x"],
  
  [y, -1.1, 1.1], grid2d, [xtics, 1], [ytics, 0.2], 
  [gnuplot_preamble, "set key bottom right;"]
)$

逆双曲線関数

$ y = \sinh^{-1} x = \mbox{arsinh}\ x = $ asinh(x) の定義域は $-\infty < x < \infty$

$ y = \cosh^{-1} x = \mbox{arcosh}\ x = $ acosh(x) の定義域は $1 \leq x < \infty$

$ y = \tanh^{-1} x = \mbox{artanh}\ x = $ atanh(x) の定義域は $-1 < x < 1$

In [19]:
plot2d(
  asinh(x), [x, -20, 20], 
  [style, [lines, 2]], 
  [legend, "sinh^{-1} x"], [ylabel, ""],
  
  [y, -4, 4], grid2d, [xtics, 5], [ytics, 1], 
  [gnuplot_preamble, "set key top left;"]
)$

Maxima の plot2d() では $x$ の範囲の異なるグラフを一緒には描けないようだ。$y = \cosh^{-1} x$ は $ 1 \leq x < \infty$ なので,$y = \sinh^{-1} x$ とは別にグラフにする。

In [20]:
plot2d(
  acosh(x), [x, 1, 20], 
  [style, [lines, 2]], 
  [legend, "cosh^{-1} x"], [ylabel, ""],
  
  [x, -20, 20], [y, -4, 4], grid2d, [xtics, 5], [ytics, 1], 
  [gnuplot_preamble, "set key top left;"]
)$

In [21]:
plot2d(
  atanh(x), [x, -0.99999, 0.99999], 
  [style, [lines, 2]], 
  [legend, "tanh^{-1} x"], [ylabel, ""],
  
  [x, -1.1, 1.1], [y, -6, 6], grid2d, [xtics, 0.2], [ytics, 2], 
  [gnuplot_preamble, "set key top left;"]
)$