文章内容源于学习:麻省理工学院公开课:单变量微积分-导数和变化率-网易公开课
大学时学的微积分,感觉要忘光了.... 唉, 重修下吧
准备工作:
(1)安装python(作为学习工具,可以求导,可以出图)。
下载A安装naconda | Individual Edition 并安装
安装完成后,使用Anaconda命令行,在命令行窗口依次运行
pip install sympy
pip install pandas
pip install matplotlib第一节 导数可以被定义为切线的斜率 (注意听课, 并使用python解决数学问题)
讲解公式:
在Anaconda navigater中打开Jyputer
一、首先画出函数 fx
# assigned 50 values from 0.1 to 3.1415... to x
x = np.linspace(0.1,np.pi,50)
y = 1 / x
plt.plot(x,y, 'c', label=' fx = 1/x ')
plt.legend(loc='upper right')
plt.show()
二、求导:
from sympy import *
x = Symbol('x')
f = 1/x
derivative_f = f.diff(x)
derivative_f
通过求x0在0.7处的切线在x轴和y轴上的截距得到切线
三、求截距
由于导数dy/dx = -1/(x*x) => y-y0 / x-x0 = -1/(x0*x0)
当y=0 可得切线在x轴的截距
x, y, x0, y0 = symbols('x y x0 y0')
expr = (y-y0)/(x-x0) + 1/(x0*x0)
expr.subs(y,0).subs(y0, 1/x0)
eq1 = Eq(-1 / (x0*(x-x0)) + 1/(x0*x0))
sol = solve(eq1)
sol
y = 0 x=2*x0 = 1.4 =>x轴的截距 [1.4, 0]
求切线在y轴上的截距:由于y = 1 / x , x 和y具有对称性,所以 当 x = 0 y=2*y0 = 2/ x0
expr = 2/x0
expr.subs(x0,0.7)
切线在y轴的截距 [0, 2.85714285714286]
四、画出切线
#画坐标轴
fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)
ax.spines['left'].set_position('zero')
ax.spines['bottom'].set_position('zero')
ax.spines['right'].set_color('none')
ax.spines['top'].set_color('none')
ax.xaxis.set_ticks_position('bottom')
ax.yaxis.set_ticks_position('left')
#画fx
x = np.linspace(0.1,np.pi,50)
y = 1 / x
plt.plot(x,y, 'm', label=' fx = 1/x ')
plt.legend(loc='upper right')
#画x = 0.7的切线
p1 = [0, 2.85714285714286] #点p1的坐标值
p2 = [1.4, 0] #点p2的坐标值
plt.plot([p1[0], p2[0]], [p1[1], p2[1]], color='b', label='tangent line of fx on x=0.7')
plt.legend(loc='upper right')
#画切点
plt.scatter(0.7, 1/0.7, c='r', label='tangent point')
plt.legend(loc='upper right')
plt.show()
上一篇:为什么要去美国留学? 下一篇:2021年深圳市孔雀计划认定办法 |