Python之高等数学(导数,微分)

在知乎上看到关于导数和微分的区别:https://www.zhihu.com/question/22199657

导数(Derivative),也叫导函数值。又名微商,是微积分中的重要基础概念。当函数y=f(x)的自变量x在一点x0上产生一个增量Δx时,函数输出值的增量Δy与自变量增量Δx的比值在Δx趋于0时的极限a如果存在,a即为在x0处的导数,记作f'(x0)或df(x0)/dx。

导数是函数的局部性质。一个函数在某一点的导数描述了这个函数在这一点附近的变化率。如果函数的自变量和取值都是实数的话,函数在某一点的导数就是该函数所代表的曲线在这一点上的切线斜率。导数的本质是通过极限的概念对函数进行局部的线性逼近。例如在运动学中,物体的位移对于时间的导数就是物体的瞬时速度

设某质点从 0时刻沿直线运动, t时刻在直线上坐标为 s,这样质点运动由函数 s = f (t) 描述。那么质点的平均速度 
那么质点在 t0 的瞬时速度为 

微分在数学中的定义:由函数B=f(A),得到A、B两个数集,在A中当dx靠近自己时,函数在dx处的极限叫作函数在dx处的微分,微分的中心思想是无穷分割。微分是函数改变量的线性主要部分。微积分的基本概念之一。

def f(x):
    return x**2
plt.figure(figsize=(12,6))
n = np.linspace(-10,10,num = 50)
plt.plot(n,f(n))
plt.xlim(-11,11)
plt.ylim(-10,110)
plt.plot([-5,f(-5)],[3,f(3)],color = "r")
print('直线斜率为%.2f' % ((f(3)-f(-5))/(3+5)))

#斜率
def ds(xm,offset):
    y = f(xm)
    y1 = f(xm+offset)
    return (y1-y)/offset
for i in np.linspace(1,0,num=100000,endpoint=False):
    print('偏移%.5f个单位距离时,斜率为:%.5f' % (i,ds(2,i)))
偏移0.00010个单位距离时,斜率为:4.00010
偏移0.00009个单位距离时,斜率为:4.00009
偏移0.00008个单位距离时,斜率为:4.00008
偏移0.00007个单位距离时,斜率为:4.00007
偏移0.00006个单位距离时,斜率为:4.00006
偏移0.00005个单位距离时,斜率为:4.00005
偏移0.00004个单位距离时,斜率为:4.00004
偏移0.00003个单位距离时,斜率为:4.00003
偏移0.00002个单位距离时,斜率为:4.00002
偏移0.00001个单位距离时,斜率为:4.00001
#斜率为4   点(2,4) 算出 y = 4x - 4
n = np.linspace(-10,10,num = 50)
plt.plot(n,f(n))
plt.xlim(-11,11)
plt.ylim(-10,110)

plt.scatter(2,f(2))
plt.plot(n,4*n-4)

连续求导
def f2(x):
    return x**4
def f2_(x):
    return 4*x**3
def f2__(x):
    return 12*x**2
def f2___(x):
    return 24*x
plt.figure(figsize = (12,6))
x = np.linspace(-10,10,num = 50)
plt.plot(x,f2(x))
plt.plot(x,f2_(x))
plt.plot(x,f2__(x))
plt.plot(x,f2___(x))

猜你喜欢

转载自blog.csdn.net/weixin_38452632/article/details/84579631