LoginSignup
1
0

More than 3 years have passed since last update.

接線の方程式問題(高校レベル)がめんどくさいので解かせる

Posted at

はじめに

微分は人工知能分野では、頻繁に使われる操作。今回は常微分での接線問題について触れる。
高校生レベルなので紙の上で解けることを前提とする。

環境

・Jupyter notebook
・julia 1.4.0
・python 3.

接線の方程式問題

関数f(x) = 3x^2+4x-5のx=1における接線の方程式を求めなさい。

紙の上での考え方

接線の方程式の公式は、

x=aの接線は
f(x)−f(a)=f'(a)(x−a)

この公式は、傾きf'(a)をもち、平行移動したものである。これの一つ一つの項を求めればいい。今回の問題ではa=1である。

\begin{align}
&f (x) = y\\
&f'(x)=6x+4\\
&f (a) = f(1) = 3・1^2+4・1-5=2\\
&f'(a)=f'(1)=6+4=10
\end{align}

これらから接線の方程式については、

y = 10*x - 8

となる。

微分をして接線の方程式

python
import sympy as sym
from sympy.plotting import plot
sym.init_printing(use_unicode=True)

# もとの関数
def originfunc(x):
    return 3*x**2+4*x-5


# 微分
def diffunc(x):
    dify = sym.diff(originfunc(x))
    return dify

if __name__ == "__main__":
    x = sym.symbols('x')
    y_1 = originfunc(1)
    print(y_1)
    #=>2
    dify_x = diffunc(x)
    print(dify_x)
    #=>6*x + 4
    dify_1 = dify_x.subs(x, 1)
    print(dify_1)
    #=>10
    # 接線の方程式
    y = dify_1*(x - 1) + y_1
    print('y =',y)
    #=>y = 10*x - 8

結果

sympy初心者には逆にめんどくさかった。

1
0
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
1
0