自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

Python實現(xiàn)之初等函數(shù)二之反函數(shù)

開發(fā) 后端
一般來說,設函數(shù)y=f(x)(x∈A)的值域是C,若找得到一個函數(shù)g(y)在每一處g(y)都等于x,這樣的函數(shù)x= g(y)(y∈C)叫做函數(shù)y=f(x)(x∈A)的反函數(shù),記作x=f-1(y) 。

 [[414222]]

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

一般來說,設函數(shù)y=f(x)(x∈A)的值域是C,若找得到一個函數(shù)g(y)在每一處g(y)都等于x,這樣的函數(shù)x= g(y)(y∈C)叫做函數(shù)y=f(x)(x∈A)的反函數(shù),記作x=f-1(y) 。反函數(shù)x=f -1(y)的定義域、值域分別是函數(shù)y=f(x)的值域、定義域。最具有代表性的反函數(shù)就是對數(shù)函數(shù)與指數(shù)函數(shù)。

  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 :Inversefunction.py 
  24. @Author :不勝人生一場醉@Date :2021/7/29 23:17  
  25. ''
  26. import matplotlib.pyplot as plt 
  27. import numpy as np 
  28.  
  29. if __name__ == '__main__'
  30.    inversefunction() 
  1. def inversefunction(): 
  2.    plt.figure(figsize=(5, 15)) 
  3.    ax = plt.gca()  # 通過gca:get current axis得到當前軸 
  4.    plt.rcParams['font.sans-serif'] = ['SimHei']  # 繪圖中文 
  5.    plt.rcParams['axes.unicode_minus'] = False  # 繪圖負號 
  6.    x = np.linspace(-2, 2, 100) 
  7.    y1 = np.power(x, 3) 
  8.    y2 = np.power(abs(x), 1 / 3) * np.sign(x) 
  9.    y3 = x 
  10.    label = 'np.power(x,3)' 
  11.    plt.plot(x, y1, label=label) 
  12.    label = 'np.power(x,1/3)' 
  13.    plt.plot(x, y2, label=label) 
  14.    # plt.plot(y1,x,label=label) 
  15.    # np.power(x,1/3)和x,y1調換一下是等價的 
  16.    label = 'y=x' 
  17.    plt.plot(x, y3, label=label) 
  18.    # 設置圖片的右邊框和上邊框為不顯示 
  19.    ax.spines['right'].set_color('none'
  20.    ax.spines['top'].set_color('none'
  21.  
  22.    # 挪動x,y軸的位置,也就是圖片下邊框和左邊框的位置 
  23.    # data表示通過值來設置x軸的位置,將x軸綁定在y=0的位置 
  24.    ax.spines['bottom'].set_position(('data', 0)) 
  25.    # axes表示以百分比的形式設置軸的位置,即將y軸綁定在x軸50%的位置 
  26.    # ax.spines['left'].set_position(('axes', 0.5)) 
  27.    ax.spines['left'].set_position(('data', 0)) 
  28.    plt.title("反函數(shù)"
  29.    plt.legend(loc='upper right'
  30.    plt.show() 
  31.  
  32.    # 反函數(shù)與原函數(shù)的復合函數(shù)等于x 
  33.    plt.figure(figsize=(5, 5)) 
  34.    ax = plt.gca()  # 通過gca:get current axis得到當前軸 
  35.    plt.rcParams['font.sans-serif'] = ['SimHei']  # 繪圖中文 
  36.    plt.rcParams['axes.unicode_minus'] = False  # 繪圖負號 
  37.    x = np.linspace(-2, 2, 100) 
  38.    y1 = np.power(x, 3) 
  39.    y2 = np.power(abs(y1), 1 / 3) * np.sign(y1) 
  40.    label = 'np.power(abs(np.power(x, 3)), 1 / 3) * np.sign(np.power(x, 3))' 
  41.    plt.plot(x, y2, label=label) 
  42.    ax.spines['right'].set_color('none'
  43.    ax.spines['top'].set_color('none'
  44.  
  45.    # 挪動x,y軸的位置,也就是圖片下邊框和左邊框的位置 
  46.    # data表示通過值來設置x軸的位置,將x軸綁定在y=0的位置 
  47.    ax.spines['bottom'].set_position(('data', 0)) 
  48.    # axes表示以百分比的形式設置軸的位置,即將y軸綁定在x軸50%的位置 
  49.    # ax.spines['left'].set_position(('axes', 0.5)) 
  50.    ax.spines['left'].set_position(('data', 0)) 
  51.    plt.title("反函數(shù)與原函數(shù)的復合函數(shù)"
  52.    plt.legend(loc='upper right'
  53.    plt.show() 

 

責任編輯:武曉燕 來源: python與大數(shù)據(jù)分析
相關推薦

2021-07-27 05:04:12

python初等函數(shù)

2021-07-30 06:58:27

python實現(xiàn)三角函數(shù)

2021-08-11 07:02:04

Python激活函數(shù)

2010-09-16 09:35:17

SQL函數(shù)

2010-07-12 11:38:24

SQL Server函

2010-09-10 14:05:12

SQL聚合函數(shù)

2013-03-04 10:03:17

Python函數(shù)式編程

2010-02-02 17:33:35

Python函數(shù)編譯

2021-03-31 07:39:18

pythonHIVEUDF函數(shù)

2022-07-07 09:03:36

Python返回函數(shù)匿名函數(shù)

2011-07-21 10:07:58

JavaScript

2010-07-12 11:06:37

SQL Server2

2020-09-04 06:32:20

Pythonshutil函數(shù)

2022-04-24 15:07:09

GPS模塊on函數(shù)鴻蒙

2016-10-13 19:11:27

JavaScript函數(shù)Web

2021-07-07 21:40:46

Rust函數(shù)勸退

2016-08-11 10:34:37

Javascript函數(shù)編程

2023-11-28 11:51:01

C++函數(shù)

2023-12-13 10:51:49

C++函數(shù)模板編程

2023-12-24 12:56:14

C++函數(shù)語言
點贊
收藏

51CTO技術棧公眾號