7
7

More than 3 years have passed since last update.

高校数学の「極限値」関連の問題をPythonで解く

Last updated at Posted at 2019-10-03

概要

 関数の極限値に関する問題(高校数学)を Python で解いていきます。練習問題と解答例の作成支援を目的としています(教員向けものです)。

問1

次の極限値を求めよ。

$$ \lim_{x \to -\infty} \frac{5x^2-x}{4-2x^2} $$

問1の解き方(参考)

分子分母を $x^2$ で割ります。

$$\lim_{x \to -\infty} \frac{5x^2-x}{4-2x^2} = \lim_{x \to -\infty} \frac{5-\frac{1}{x}}{\frac{4}{x^2}-2} = -\frac{5}{2} $$

問1の解を与えるPythonプログラム

sympy を利用して解きます。sympy は、記号計算(数式処理)のパッケージです。無限大 $\infty$ は sympy.oo で与えます。

Python
from sympy import oo, limit, Symbol
x = Symbol('x')
fx = ( 5*x**2 - x ) / ( 4 - 2*x**2 )
ans = limit(fx, x, -oo)
print(f'解:{ans}')

実行結果

解:-5/2

おまけ1

分数関数 $\frac{5x^2-x}{4-2x^2} $ のグラフを描いてみます。$x\to -\infty$ を見るために、$x$軸をログスケールにします。

import numpy as np
import matplotlib.pyplot as plt
from sympy import Symbol,solve

# 定義域を確認
g = ( 4 - 2*x**2 ) # 分母
sx = solve(g)
tmp = ', '.join(map(str,sx))
print(f'分母 ( {g} ) がゼロになるのは(定義域から除外されるのは) x= {tmp} ')

# グラフの描画 ここからは numpy を利用
x1 = -np.logspace(-2, 4, num=100)[::-1] # -10e4  ~ -10e-2
x2 =  np.logspace(-2, 4, num=100)       #  10e-2 ~  10e4
x  =  np.concatenate([x1,x2])
f = lambda x : ( 5*x**2 - x ) / ( 4 - 2*x**2 ) 
y = f(x)
plt.figure(dpi=120)
plt.plot(x, y, marker='.')
plt.ylim(-10,10)
plt.xscale('symlog') # 対称ログスケール
plt.show()

おまけ1の実行結果

分母 ( -2*x**2 + 4 ) がゼロになるのは(定義域から除外されるのは) x= -sqrt(2), sqrt(2) 

ダウンロード.png

グラフからも、$x\to -\infty$ で、$-2.5$ に収束することが推測できます。

おまけ2

定義域から外れる $x= \pm\sqrt{2}$ でどのような値に近づくのかを見てみます。ここでは $\sqrt{2}$ について、右側($\sqrt{2}+\delta$)からと左側($\sqrt{2}-\delta$)からのアプローチしたときの値を見てみます。つまり、$x\to \sqrt{2}^{+}$、$x\to\sqrt{2}^{-}$ のときの極限値を求めます。

sympy.limit() の第4引数に、'+' または '-' を設定します。

Python
from sympy import limit, Symbol,sqrt
x = Symbol('x')
fx = ( 5*x**2 - x ) / ( 4 - 2*x**2 )
ans1 = limit(fx, x, sqrt(2), '+')
ans2 = limit(fx, x, sqrt(2), '-')
print(f'解:{ans1}, {ans2}')

おまけ2の実行結果

グラフの結果と一致します。

解:-oo, oo

問2

次の極限値を求めよ。

$$ \lim_{x \to \infty} (\sqrt{x^2+1}-x ) $$

問2の解き方(参考)

\begin{align}
\lim_{x \to \infty} (\sqrt{x^2+1}-x )  & = \lim_{x \to \infty} \frac{(\sqrt{x^2+1}-x)(\sqrt{x^2+1}+x)}{\sqrt{x^2+1}+x}  \\
& =  \lim_{x \to \infty} \frac{(x^2+1)-x^2}{\sqrt{x^2+1}+x} \\
& =  \lim_{x \to \infty} \frac{1}{\sqrt{x^2+1}+x} \\
& = 0
\end{align}

問2の解を与えるPythonプログラム

Python
from sympy import oo, limit, Symbol, sqrt
x = Symbol('x')
fx = sqrt(x**2+1)-x
ans = limit(fx, x, oo)
print(f'解:{ans}')

実行結果

解:0
7
7
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
7