Differentiation is a frequently used operation in the field of artificial intelligence. This time, I will touch on the tangent problem in ordinary differential equations. Since it is a high school student level, it is assumed that it can be solved on paper.
・ Jupyter notebook ・ Julia 1.4.0 ・ Python 3.
Function f(x) = 3x^2+4x-5 x=Find the tangent equation at 1.
The formula for the tangent equation is
x=The tangent to a is
f(x)−f(a)=f'(a)(x−a)
This formula has a slope f'(a) and is translated. You can find each item of this. In this problem, 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}
For the tangent equations from these,
y = 10*x - 8
Will be.
python
import sympy as sym
from sympy.plotting import plot
sym.init_printing(use_unicode=True)
#Original function
def originfunc(x):
return 3*x**2+4*x-5
#differential
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
#Tangent equation
y = dify_1*(x - 1) + y_1
print('y =',y)
#=>y = 10*x - 8
On the contrary, it was annoying for sympy beginners.