日本综合一区二区|亚洲中文天堂综合|日韩欧美自拍一区|男女精品天堂一区|欧美自拍第6页亚洲成人精品一区|亚洲黄色天堂一区二区成人|超碰91偷拍第一页|日韩av夜夜嗨中文字幕|久久蜜综合视频官网|精美人妻一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時(shí)間:8:30-17:00
你可能遇到了下面的問(wèn)題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營(yíng)銷解決方案
Python實(shí)現(xiàn)之導(dǎo)數(shù)

本文轉(zhuǎn)載自微信公眾號(hào)「python與大數(shù)據(jù)分析」,作者一只小小鳥(niǎo)鳥(niǎo) 。轉(zhuǎn)載本文請(qǐng)聯(lián)系python與大數(shù)據(jù)分析公眾號(hào)。

導(dǎo)數(shù)(Derivative),也叫導(dǎo)函數(shù)值。又名微商,是微積分中的重要基礎(chǔ)概念。當(dāng)函數(shù)y=f(x)的自變量x在一點(diǎn)x0上產(chǎn)生一個(gè)增量Δx時(shí),函數(shù)輸出值的增量Δy與自變量增量Δx的比值在Δx趨于0時(shí)的極限a如果存在,a即為在x0處的導(dǎo)數(shù),記作f'(x0)或df(x0)/dx。

不是所有的函數(shù)都有導(dǎo)數(shù),一個(gè)函數(shù)也不一定在所有的點(diǎn)上都有導(dǎo)數(shù)。若某函數(shù)在某一點(diǎn)導(dǎo)數(shù)存在,則稱其在這一點(diǎn)可導(dǎo),否則稱為不可導(dǎo)。然而,可導(dǎo)的函數(shù)一定連續(xù);不連續(xù)的函數(shù)一定不可導(dǎo)。

切線指的是一條剛好觸碰到曲線上某一點(diǎn)的直線。更準(zhǔn)確地說(shuō),當(dāng)切線經(jīng)過(guò)曲線上的某點(diǎn)(即切點(diǎn))時(shí),切線的方向與曲線上該點(diǎn)的方向是相同的。平面幾何中,將和圓只有一個(gè)公共交點(diǎn)的直線叫做圓的切線。

法線(normal line),是指始終垂直于某平面的直線。在幾何學(xué)中,法線指平面上垂直于曲線在某點(diǎn)的切線的一條線。法線也應(yīng)用于光學(xué)的平面鏡反射上。

 
 
 
 
  1. #!/usr/bin/env python 
  2. # -*- coding: UTF-8 -*- 
  3. #                     _ooOoo_ 
  4. #                   o8888888o 
  5. #                    88" . "88 
  6. #                 ( | -  _  - | ) 
  7. #                     O\ = /O 
  8. #                 ____/`---'\____ 
  9. #                  .' \\| |// `. 
  10. #                 / \\|||:|||// \ 
  11. #               / _|||||-:- |||||- \ 
  12. #                | | \\\ - /// | | 
  13. #              | \_| ''\---/'' | _/ | 
  14. #               \ .-\__ `-` ___/-. / 
  15. #            ___`. .' /--.--\ `. . __ 
  16. #         ."" '< `.___\_<|>_/___.' >'"". 
  17. #       | | : `- \`.;`\  _ /`;.`/ - ` : | | 
  18. #          \ \ `-. \_ __\ /__ _/ .-` / / 
  19. #      ==`-.____`-.___\_____/___.-`____.-'== 
  20. #                     `=---=' 
  21. ''' 
  22. @Project :pythonalgorithms  
  23. @File :derivatives.py 
  24. @Author :不勝人生一場(chǎng)醉@Date :2021/8/1 0:17  
  25. ''' 
  26. import matplotlib.pyplot as plt 
  27. import numpy as np 
  28. import math 
  29. import sympy 
  30. import mpl_toolkits.axisartist as axisartist  # 導(dǎo)入坐標(biāo)軸加工模塊 
  31.  
  32. if __name__ == '__main__': 
  33.     quadraticderivativeplot() 
  34.     exponentialderivativeplot() 
  35.     arccscderivativeplot() 
 
 
 
 
  1. # 導(dǎo)數(shù)(Derivative),也叫導(dǎo)函數(shù)值。又名微商,是微積分中的重要基礎(chǔ)概念。 
  2. # 當(dāng)函數(shù)y=f(x)的自變量x在一點(diǎn)x0上產(chǎn)生一個(gè)增量Δx時(shí),函數(shù)輸出值的增量Δy與自變量增量Δx的比值在Δx趨于0時(shí)的極限a如果存在,a即為在x0處的導(dǎo)數(shù),記作f'(x0)或df(x0)/dx。 
  3. # 不是所有的函數(shù)都有導(dǎo)數(shù),一個(gè)函數(shù)也不一定在所有的點(diǎn)上都有導(dǎo)數(shù)。 
  4. # 若某函數(shù)在某一點(diǎn)導(dǎo)數(shù)存在,則稱其在這一點(diǎn)可導(dǎo),否則稱為不可導(dǎo)。然而,可導(dǎo)的函數(shù)一定連續(xù);不連續(xù)的函數(shù)一定不可導(dǎo)。 
  5. def quadraticderivativeplot(): 
  6.     plt.figure(figsize=(5, 12)) 
  7.     ax = plt.gca()  # 通過(guò)gca:get current axis得到當(dāng)前軸 
  8.     plt.rcParams['font.sans-serif'] = ['SimHei']  # 繪圖中文 
  9.     plt.rcParams['axes.unicode_minus'] = False  # 繪圖負(fù)號(hào) 
  10.     x = np.linspace(-2, 2, 200) 
  11.  
  12.     y = x ** 2 
  13.     label = '函數(shù)=x**2的曲線' 
  14.     plt.plot(x, y, label=label) 
  15.     yd = 2 * x 
  16.     label = '導(dǎo)數(shù)線=2*x的曲線' 
  17.     plt.plot(x, yd, label=label) 
  18.     a = 1 
  19.     ad = a ** 2 
  20.     plt.plot(a, ad, 'og', label='x=1的某個(gè)點(diǎn)') 
  21.     # y=ax+b,已知a=2,x=1,y=1,求b 
  22.     b = ad - 2 * a 
  23.     # 準(zhǔn)備畫(huà)切線的數(shù)據(jù) 
  24.     al = np.linspace(-2, 2, 200) 
  25.     yl = 2 * al + b 
  26.     label = 'x=1的切線' 
  27.     plt.plot(al, yl, label=label) 
  28.     # 準(zhǔn)備畫(huà)法線的數(shù)據(jù),切線斜率=法線斜率的負(fù)數(shù) 
  29.     b = ad + 2 * a 
  30.     al = np.linspace(-2, 2, 200) 
  31.     yl = -2 * al + b 
  32.     label = 'x=1的法線' 
  33.     plt.plot(al, yl, label=label) 
  34.     # 求導(dǎo)函數(shù) 
  35.     x = sympy.Symbol('x') 
  36.     f1 = x ** 2 
  37.     # 參數(shù)是函數(shù)與變量 
  38.     f1_ = sympy.diff(f1, x) 
  39.     print(f1_) 
  40.  
  41.     # 設(shè)置圖片的右邊框和上邊框?yàn)椴伙@示 
  42.     ax.spines['right'].set_color('none') 
  43.     ax.spines['top'].set_color('none') 
  44.  
  45.     # 挪動(dòng)x,y軸的位置,也就是圖片下邊框和左邊框的位置 
  46.     # data表示通過(guò)值來(lái)設(shè)置x軸的位置,將x軸綁定在y=0的位置 
  47.     ax.spines['bottom'].set_position(('data', 0)) 
  48.     # axes表示以百分比的形式設(shè)置軸的位置,即將y軸綁定在x軸50%的位置 
  49.     # ax.spines['left'].set_position(('axes', 0.5)) 
  50.     ax.spines['left'].set_position(('data', 0)) 
  51.     plt.title("二次函數(shù)、導(dǎo)數(shù)曲線及某點(diǎn)的法線、切線") 
  52.     plt.legend(loc='upper right') 
  53.     plt.show() 

 
 
 
 
  1. # 指數(shù)函數(shù)的導(dǎo)數(shù) 
  2. # 指數(shù)函數(shù) y=a**x 
  3. # 指數(shù)函數(shù)的導(dǎo)數(shù)為 y=a**x*ln(a) 
  4. def exponentialderivativeplot(): 
  5.     plt.figure(figsize=(5, 12)) 
  6.     ax = plt.gca()  # 通過(guò)gca:get current axis得到當(dāng)前軸 
  7.     plt.rcParams['font.sans-serif'] = ['SimHei']  # 繪圖中文 
  8.     plt.rcParams['axes.unicode_minus'] = False  # 繪圖負(fù)號(hào) 
  9.     a = 2 
  10.     x = np.linspace(-2, 2, 200) 
  11.     y = np.power(a, x) 
  12.     yd = np.power(a, x) * np.log(a) 
  13.     label = '函數(shù)=a**x的曲線' 
  14.     plt.plot(x, y, label=label) 
  15.     label = '導(dǎo)數(shù)線=a**x的曲線' 
  16.     plt.plot(x, yd, label=label) 
  17.  
  18.     xpoint = 1 
  19.     ypoint = np.power(a, xpoint) 
  20.     plt.plot(xpoint, ypoint, 'og', label='x=1的某個(gè)點(diǎn)') 
  21.     # 斜率slope=導(dǎo)數(shù),求截距intercept 
  22.     slope = math.pow(a, xpoint) * math.log(a, np.e) 
  23.     # y=ax+b,已知a,x,y,求b 
  24.     intercept = ypoint - slope * xpoint 
  25.     # 準(zhǔn)備畫(huà)切線的數(shù)據(jù) 
  26.     yl = x * slope + intercept 
  27.     # print(slope,intercept,yl) 
  28.     label = 'x=1的切線' 
  29.     plt.plot(x, yl, label=label) 
  30.     # 準(zhǔn)備畫(huà)法線的數(shù)據(jù),切線斜率=法線斜率的負(fù)數(shù) 
  31.     # y=ax+b,已知x,y,-a,求b 
  32.     intercept = ypoint + slope * xpoint 
  33.     yl = -x * slope + intercept 
  34.     label = 'x=1的法線' 
  35.     plt.plot(x, yl, label=label) 
  36.     # # 求導(dǎo)函數(shù) 
  37.     # x = sympy.Symbol('x') 
  38.     # f1 = x**2 
  39.     # # 參數(shù)是函數(shù)與變量 
  40.     # f1_ = sympy.diff(f1, x) 
  41.     # print(f1_) 
  42.     # 設(shè)置圖片的右邊框和上邊框?yàn)椴伙@示 
  43.     ax.spines['right'].set_color('none') 
  44.     ax.spines['top'].set_color('none') 
  45.  
  46.     # 挪動(dòng)x,y軸的位置,也就是圖片下邊框和左邊框的位置 
  47.     # data表示通過(guò)值來(lái)設(shè)置x軸的位置,將x軸綁定在y=0的位置 
  48.     ax.spines['bottom'].set_position(('data', 0)) 
  49.     # axes表示以百分比的形式設(shè)置軸的位置,即將y軸綁定在x軸50%的位置 
  50.     # ax.spines['left'].set_position(('axes', 0.5)) 
  51.     ax.spines['left'].set_position(('data', 0)) 
  52.     plt.title("指數(shù)函數(shù)、導(dǎo)數(shù)曲線及某點(diǎn)的法線、切線") 
  53.     plt.legend(loc='upper right') 
  54.     plt.show() 

 
 
 
 
  1. # 常用導(dǎo)數(shù)公式表如下:# 
  2. # c'=0(c為常數(shù)) 
  3. # (x^a)'=ax^(a-1),a為常數(shù)且a≠0 
  4. # (a^x)'=a^xlna 
  5. # (e^x)'=e^x# 
  6. # (logax)'=1/(xlna),a>0且 a≠1 
  7. # (lnx)'=1/x 
  8. # (sinx)'=cosx 
  9. # (cosx)'=-sinx 
  10. # (tanx)'=(secx)^2 
  11. # (secx)'=secxtanx 
  12. # (cotx)'=-(cscx)^2 
  13. # (cscx)'=-csxcotx 
  14. # (arcsinx)'=1/√(1-x^2) 
  15. # (arccosx)'=-1/√(1-x^2) 
  16. # (arctanx)'=1/(1+x^2) 
  17. # (arccotx)'=-1/(1+x^2) 
  18. # arcsinx函數(shù)的導(dǎo)數(shù) 
  19. # arcsinx函數(shù) 
  20. # arcsinx函數(shù)的導(dǎo)數(shù)為 1/√(1-x^2) 
  21. def arccscderivativeplot(): 
  22.     plt.figure(figsize=(10, 5)) 
  23.     ax = plt.gca()  # 通過(guò)gca:get current axis得到當(dāng)前軸 
  24.     plt.rcParams['font.sans-serif'] = ['SimHei']  # 繪圖中文 
  25.     plt.rcParams['axes.unicode_minus'] = False  # 繪圖負(fù)號(hào) 
  26.     x = np.append(np.linspace(0.01, np.pi / 2 - 0.01, 120), 
  27.                   np.linspace(np.pi / 2 + 0.01, np.pi - 0.01, 120)) 
  28.     y = 1 / np.cos(x) 
  29.     # 正割函數(shù) sec(x)=1/cos(x) 
  30.     # 反正割函數(shù) 顛倒x,y值即可 
  31.     label = '函數(shù)為np.arcsecx(x)的曲線' 
  32.     plt.plot(y, x, label=label) 
  33.     x = np.linspace(-0.99, 0.99, 120) 
  34.     yd = 1 / np.sqrt(1 - np.power(x, 2)) 
  35.     label = '導(dǎo)數(shù)線為np.arcsecx(x)的曲線' 
  36.     plt.plot(x, yd, label=label) 
  37.     # 設(shè)置圖片的右邊框和上邊框?yàn)椴伙@示 
  38.     ax.spines['right'].set_color('none') 
  39.     ax.spines['top'].set_color('none') 
  40.  
  41.     # 挪動(dòng)x,y軸的位置,也就是圖片下邊框和左邊框的位置 
  42.     # data表示通過(guò)值來(lái)設(shè)置x軸的位置,將x軸綁定在y=0的位置 
  43.     ax.spines['bottom'].set_position(('data', 0)) 
  44.     # axes表示以百分比的形式設(shè)置軸的位置,即將y軸綁定在x軸50%的位置 
  45.     # ax.spines['left'].set_position(('axes', 0.5)) 
  46.     ax.spines['left'].set_position(('data', 0)) 
  47.     plt.title("arcsin函數(shù)、導(dǎo)數(shù)曲線") 
  48.     plt.legend(loc='upper right') 
  49.     plt.show() 

網(wǎng)站標(biāo)題:Python實(shí)現(xiàn)之導(dǎo)數(shù)
分享URL:http://www.dlmjj.cn/article/djiocos.html