第三单元 用python学习微积分(十九)FTC2(下)和定积分在对数和几何上的应用

本文内容来自于学习麻省理工学院公开课:单变量微积分-定积分在对数和几何上的应用-网易公开课

概率密度_百度百科

概率密度是什么意思_百度知道

正态分布(高斯分布)、Q函数、误差函数、互补误差函数 - htj10 - 博客园

正态分布_百度百科

通信原理授课教案第一章一、通信系统的组成1、基本的点对点通信系统 (高斯过程)

开发环境准备:CSDN

目录

一、FTC2

1、 由 ​得到对数的定义​

(1) L(1) = 0 同时 x>0时, L 一直增长( L'(x) >0 , x>0)

(2)  ​

二、例子

1、 ​

(1) ​

(2)  由于下标为0,所以 F(0) = 0

(3)  ​

(4)   这个函数是奇函数(F(-x) = - F(x))

2、另外几个使用积分发现的新的函数,(不能使用基本函数表示 "超越函数")

三、曲线之间的面积

1、找到曲线 ​ 和 y = x - 2 之间的面积, 把式子一带入式子2可得到交点坐标

(1)  方法一、

(2)  方法二 、


一、FTC2

\frac{d}{dx} \int_{a}^{x} f(t)dt = f(x) ( f(a) = 0)

1、 由 y' = \frac{1}{x}得到对数的定义L(x) = \int_{1}^{x} \frac{dt}{t}

L'(x) = \frac{1}{x}; L(1) = \int_{1}^{1} \frac{dt}{t} = 0

L''(x) = \frac{-1}{x^2}(下凹),L(1) = 0, L'(1) = \frac{1}{1} = 1(x=1点处切线斜率为1), 另ln(e) = 1

有了这些性质可以粗画一个近似曲线

from sympy import *
import numpy as np 

import matplotlib.pyplot as plt 

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')
ax.set_aspect(1 ) 

def DrawXY(xFrom,xTo,steps,expr,color,label,plt):
    yarr = []
    xarr = np.linspace(xFrom ,xTo, steps) 
    for xval in xarr:
        yval = expr.subs(x,xval)
        yarr.append(yval)
    y_nparr = np.array(yarr) 
    plt.plot(xarr, y_nparr, c=color, label=label)    

def DrawInt(xFrom,xTo,steps,expr,color,plt, label=''):
    if(xFrom < 0 and xTo < 0):
        DrawIntNegative(xFrom,xTo,steps,expr,color,plt, label)
    else:
        if(xFrom > 0 and xTo > 0):
            DrawIntPostive(xFrom,xTo,steps,expr,color,plt, label)
        else:
            DrawIntNegative(xFrom,0,steps,expr,color,plt, label)
            DrawIntPostive(0,xTo,steps,expr,color,plt, label)
    
def DrawIntNegative(xFrom1,xTo1,steps,expr,color,plt, label=''):
    xFrom = 0 - xTo1
    xTo = 0 - xFrom1
    width = (xTo - xFrom)/steps
    xarr = []
    yarr = []
    area = 0
    xprev = xFrom
    yvalAll =  0
    xarr.append(0)
    yarr.append(0)
    for step in range(steps):
        yval = expr.subs(x,xprev)
        area += width * yval
        xarr.append(0-xprev)
        yarr.append(0-area)
        xprev= xprev + width
    plt.plot(xarr, yarr, c=color, label =label)
    
def DrawIntPostive(xFrom,xTo,steps,expr,color,plt, label=''):
    width = (xTo - xFrom)/steps
    xarr = []
    yarr = []
    area = 0
    xprev = xFrom
    yvalAll =  0
    xarr.append(0)
    yarr.append(0)
    for step in range(steps):
        yval = expr.subs(x,xprev)
        area += width * yval
        xarr.append(xprev)
        yarr.append(area)
        xprev= xprev + width
    plt.plot(xarr, yarr, c=color, label =label)    
        
def DrawRects(xFrom,xTo,steps,expr,color,plt, label=''):
    width = (xTo - xFrom)/steps
    xarrRect = []
    yarrRect = []
    area = 0
    xprev = xFrom
    yvalAll =  0
    for step in range(steps):
        yval = expr.subs(x,xprev + width)
        xarrRect.append(xprev)
        xarrRect.append(xprev)
        xarrRect.append(xprev + width)
        xarrRect.append(xprev + width)
        xarrRect.append(xprev)
        yarrRect.append(0)
        yarrRect.append(yval)
        yarrRect.append(yval)
        yarrRect.append(0)
        yarrRect.append(0)
        area += width * yval
        plt.plot(xarrRect, yarrRect, c=color)    
        xprev= xprev + width
        yvalAll += yval
    print('============================')    
    if len(label)!=0:
        print(label)    
    print('============================')
    print('width = ', width)
    print('ave = ', yvalAll / steps)
    print('area = ',area)
    areaFinal = (integrate(expr, (x,xFrom,xTo)))
    print ('area final = ',areaFinal)
    print ('ave final = ', areaFinal / (xTo - xFrom))

def TangentLine(exprY,x0Val,xVal):
    diffExpr = diff(exprY)
    x1,y1,xo,yo = symbols('x1 y1 xo yo')
    expr = (y1-yo)/(x1-xo) - diffExpr.subs(x,x0Val)
    eq = expr.subs(xo,x0Val).subs(x1,xVal).subs(yo,exprY.subs(x,x0Val))
    eq1 = Eq(eq,0)
    solveY = solve(eq1)
    return xVal,solveY

def DrawTangentLine(exprY, x0Val,xVal1, xVal2, clr, txt):
    x1,y1 = TangentLine(exprY, x0Val, xVal1)
    x2,y2 = TangentLine(exprY, x0Val, xVal2)
    plt.plot([x1,x2],[y1,y2], color = clr, label=txt)
    
def Newton(expr, x0):
    ret = x0 - expr.subs(x, x0)/ expr.diff().subs(x,x0)
    return ret

   
x = symbols('x')
expr = ln(x)

DrawXY(0.2,4,100,expr,'blue','L = ln(x)',plt)
DrawTangentLine(expr, 1, 0.1, 5, 'g', "L'(1)")

x = symbols('x')
expr = x**0
DrawXY(0.2,4,100,expr,'gray','y=1',plt)

plt.legend(loc='lower right')
plt.show()

这里老师提问, 为啥当 x<1时 L(x) < 0 ?

(1) L(1) = 0 同时 x>0时, L 一直增长( L'(x) >0 , x>0)

(2)  L(x) = \int_{1}^{x}\frac{dt}{t} = - \int_{x}^{1} \frac{dt}{t}

证明: L(ab) = L(a) + L(b)

\int_{1}^{ab} \frac{dt}{t} = \int_{1}^{a} \frac{dt}{t} + \int_{a}^{ab} \frac{dt}{t} = L(a) + \int_{a}^{ab} \frac{dt}{t}

考虑 \int_{a}^{ab}\frac{dt}{t}

设 t=au, dt = adu,

考虑积分du的下标,由于t最小值为 a,t=au,u最小值为1,由于t最大值为ab, u最大值为b

所以 \int_{a}^{ab}\frac{dt}{t} = \int_{1}^{b} \frac{du}{u} = L(b)

所以 \int_{1}^{ab} \frac{dt}{t} = L(a) + \int_{a}^{ab} \frac{dt}{t} = L(a) + L(b)

二、例子

1、 F(x) = \int_{0}^{x} e^{-t^2}dt

由式子可知

(1) F'(x) = e^{-x^2} (F'(x) > 0, F'(0) = 1)

(2)  由于下标为0,所以 F(0) = 0

(3)  F''(x) = -2xe^{-x^2} (F''(x) < 0, x>0 ......F''(x)>0, x<0)

(4)   这个函数是奇函数(F(-x) = - F(x))

这里我们要考虑下积分的定义,也就是曲线和x轴围成的面积, 而面积的定义是x*y, 所以而当x和y不同号时,所得积分的结果为负。而老师得到这个结论是因为曲线e^{-x^2} 是据 y 轴对称的, 所以可以看出它所围成的面积符合奇函数的定义

x = symbols('x')
expr = np.e**(-x**2)
DrawXY(-5,5,100,expr,'b','e**(-x**2)',plt)
DrawRects(-5,0,100,expr,'r',plt, '')
DrawRects(5,0,100,expr,'g',plt, '')
plt.legend(loc='lower right')
plt.show()

所以这个就是通过这些性质得到的粗画的结果,另外老师特别强调了下,如果知道了这个函数是奇函数,我们可以通过奇函数的性质很快找到结果。(即第一象限的图形先通过x轴在第四象限做镜像,然后这个镜像再通过y轴在第三象限做镜像,于是就有了第三象限的图形。)

我在上面代码中添加函数DrawInt,以计算分块矩形面积的方式模拟积分函数, 结果不准确,只是用来看看曲线

x = symbols('x')
expr = np.e**(-x**2)
DrawInt(-2,2,750,expr,'b',plt,'integrate(e**(-x**2))')
plt.legend(loc='lower right')
plt.show()

老师给出 \lim_{x\rightarrow \infty} F(x) = \frac{\sqrt{\pi}}{2}\lim_{x\rightarrow -\infty} F(x) = -\frac{\sqrt{\pi}}{2} , (这个极限值不知道怎么算的

误差函数:erf(x) = \frac{2}{\sqrt{\pi}} \int_{0}^{x} e^{-t^2}dt = \frac{2}{\sqrt{\pi}}F(x)(-1<F(x)<1)

expr = erf(x)
DrawXY(-2,2,100,expr,'g','erf(x)',plt)
plt.legend(loc='lower right')
plt.show()

​要理解误差函数,这里查了些资料:(我的理解不一定正确)

x = symbols('x')
expr = np.e**(-x**2)

DrawXY(0,1.75,100,expr,'red','f(x) = erf(1.75)',plt)
DrawXY(1.75,5,100,expr,'green','f(x) = erfc(1.75)',plt)

DrawRects(0,1.75,50,expr,'red',plt)
DrawRects(1.75,5,50,expr,'green',plt)
print('erf(1.75)=',erf(1.75))
print('erfc(1.75)=',erfc(1.75))
plt.legend(loc='upper right')

首先公式 erf(x) = \frac{2}{\sqrt{\pi}} \int_{0}^{x} e^{-t^2}dt中的 e^{-t^2}是一个标准正态分布的函数, 它代表了x的概率密度,当对这个式子求取积分时计算的是函数值分布在这个范围内的概率。

如上图中,当求取函数 e^{-t^2} 的值落在 x\in(0,1.75)内概率时使用函数erf(1.75), 而不在这个范围内的概率则是 1-erf(1.75) 也就是erfc(1.75)。所以这个函数应该可以帮助计算某些符合正态分布的统计数据的取值概率。

2、另外几个使用积分发现的新的函数,(不能使用基本函数表示 "超越函数")

 c(x) = \int_{0}^{x} cos(t^2)dt(菲涅耳(Fresnel)积分)

s(x) = \int{0}^{x} sin(t^2)dt(菲涅耳(Fresnel)积分)

H(x) = \int_{0}^{x} \frac{sin(t)}{t} dt(在傅里叶分析中出现)

Li(x) = \int_{2}^{x} \frac{dt}{ln(t)}        (Li(x)的值约等于小于x的素数个数, 黎曼猜想)

三、曲线之间的面积

1、找到曲线 x= y^2 和 y = x - 2 之间的面积, 把式子一带入式子2可得到交点坐标

x = symbols('x')
expr = x**0.5
DrawXY(0,5,100,expr,'green','x = y**2',plt)
expr = 0- x**0.5
DrawXY(0,5,100,expr,'green','',plt)
expr = x-2
DrawXY(0,5,100,expr,'red','y = x-2',plt)

y = symbols("y")
expr = y**2 -( y + 2)
eqy = Eq(expr,0)
solb = solve(eqy)

plt.plot([1,1],[-2,4], color = 'gray', label = 'x=1')
    
plt.scatter(solb[0]+2,solb[0], c='r', label='(' + format(solb[0]+2) + ',' + format(solb[0]) + ')')
plt.scatter(solb[1]+2,solb[1], c='r', label='(' + format(solb[1]+2) + ',' + format(solb[1]) + ')')

plt.legend(loc='lower right')
plt.show()

(1)  方法一、

围成的图形在x=1左侧面积 = \int_{0}^{1} (\sqrt x -(-\sqrt x))dx

求围成的图形在这个范围内(0,1) 的面积, 由于 y^2 =x,所以这个曲线在x轴上方的部分为 y = \sqrt x , 而 x 轴下面部分为 y=- \sqrt x,注意比对式子的各个部分。

围成的图形在x=1右侧面积 = \int_{1}^{4} (\sqrt x -(x-2))dx

总面积 = \int_{0}^{1} (\sqrt x -(-\sqrt x))dx + \int_{1}^{4} (\sqrt x -(x-2))dx

= (\frac{2}{3}x^{\frac{3}{2}}+ \frac{2}{3}x^{\frac{3}{2}}) |_{0}^{1} + (\frac{2}{3}x^{\frac{3}{2}} -\frac{1}{2}x^2+2)|_{1}^{4}

=\frac{4}{3} - 0 + (\frac{16}{3} -8+ 8) -(\frac{2}{3} - \frac{1}{2} +2) = \frac{20}{3} - \frac{13}{6} = \frac{27}{6} = \frac{9}{2} = 4.5

x = symbols('x')
expr = x**0.5 + x**0.5
left = float(integrate(expr, (x,0,1)))

expr1 = x**0.5 - x+2
right = float(integrate(expr1, (x,1,4)))
print(left + right)

4.5

(2)  方法二 、

左侧: x = y^2

右侧: y = x-2

面积 = \int_{-1}^{2}((y+2)-y^2)dy

当y = 0,y=1时,y+2 >y^2 , 看出我们求面积的部分y+2在上方

\frac{1}{2} y^2 + 2y - \frac{y^3}{3}|_{-1}^{2} =2 + 4 -\frac{8}{3} -(\frac{1}{2} -2 +\frac{1}{3}) =4.5

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Bullseye

您的鼓励是我最大的动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值