欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

python/Matplotlib繪制復(fù)變函數(shù)圖像教程

 更新時間:2019年11月21日 09:19:08   作者:落葉_小唱  
今天小編就為大家分享一篇python/Matplotlib繪制復(fù)變函數(shù)圖像教程,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧

今天發(fā)現(xiàn)sympy依賴的庫mpmath里也有很多數(shù)學(xué)函數(shù),其中也有在復(fù)平面繪制二維圖的函數(shù)cplot,具體例子如下

from mpmath import *

def f1(z):
 return z

def f2(z):
 return z**3

def f3(z):
 return (z**4-1)**(1/4)

def f4(z):
 return 1/z

def f5(z):
 return atan(z)

def f6(z):
 return sqrt(z)

cplot(f1)
cplot(f2)
cplot(f3)
cplot(f4)
cplot(f5)
cplot(f6)

參照matlab繪制復(fù)變函數(shù)的例子,使用python實現(xiàn)繪制復(fù)變函數(shù)圖像,網(wǎng)上還沒搜到相關(guān)的文章,在這里分享出來供大家學(xué)習(xí)。

'''
參照matlab繪制復(fù)變函數(shù)的例子,創(chuàng)建函數(shù)cplxgrid,cplxmap,cplxroot
'''
# 1.導(dǎo)入相關(guān)庫
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import *

# 2.創(chuàng)建函數(shù)
def cplxgrid(m):
 '''Return polar coordinate complex grid.

 Parameters
 ----------
 m: int

 Returns
 ----------
 z: ndarray,with shape (m+1)-by-(2*(m+1))
 '''
 m = m
 r = np.arange(0,m).reshape(m,1) / m
 theta = np.pi * np.arange(-m,m) / m
 z = r * np.exp(1j * theta)

 return z

def cplxroot(n=3,m=20):
 '''
 cplxroot(n): renders the Riemann surface for the n-th root
 cplxroot(): renders the Riemann surface for the cube root.
 cplxroot(n,m): uses an m-by-m grid. Default m = 20.

 Use polar coordinates, (r,theta).
 Use polar coordinates, (r,theta).

 Parameters
 ----------
 n: n-th root
 m: int

 Returns
 ----------
 None: Plot the Riemann surface
 '''
 m = m+1
 r = np.arange(0,m).reshape(m,1) / m
 theta = np.pi * np.arange(-n * m, n * m) / m
 z = r * np.exp(1j * theta)
 s = r * (1/n) * np.exp(1j * theta / n)
 fig = plt.figure()
 ax = fig.add_subplot(111,projection='3d')
 # ax.plot_surface(np.real(z),np.imag(z),np.real(s),color = np.imag(s))
 ax.plot_surface(np.real(z),np.imag(z),np.real(s),cmap = plt.cm.hsv)
 ax.set_xlim((-1,1))
 ax.set_ylim((-1,1))
 ax.set_xlabel('Real')
 ax.set_ylabel('Imag')
 ax.set_xticks([])
 ax.set_yticks([])
 ax.set_zticks([])
 ax.set_autoscalez_on(True)#z軸自動縮放 
 ax.grid('on')
 plt.show()

def cplxmap(z,cfun):
 '''
 Plot a function of a complex variable.

 Parameters
 ----------
 z: complex plane
 cfun: complex function to plot

 Returns
 ----------
 None: Plot the surface of complex function
 '''
 blue = 0.2
 x = np.real(z)
 y = np.imag(z)
 u = np.real(cfun)
 v = np.imag(cfun)
 M = np.max(np.max(u))#復(fù)變函數(shù)實部最大值
 m = np.min(np.min(u))#復(fù)變函數(shù)實部最大值
 s = np.ones(z.shape)
 fig = plt.figure()
 ax = fig.add_subplot(111,projection='3d')
 # 投影部分用線框圖
 surf1 = ax.plot_wireframe(x,y,m*s,cmap=plt.cm.hsv)
 surf2 = ax.plot_surface(x,y,u,cmap=plt.cm.hsv)

 #繪制復(fù)變函數(shù)1/z時會出錯,ValueError: Axis limits cannot be NaN or Inf
 # ax.set_zlim(m, M) 
 ax.set_xlim((-1,1))
 ax.set_ylim((-1,1))
 ax.set_xlabel('Real')
 ax.set_ylabel('Imag')
 ax.set_xticks([])
 ax.set_yticks([])
 ax.set_zticks([])
 ax.set_autoscalez_on(True)#z軸自動縮放

 ax.grid('on')
 plt.show()

def _test_cplxmap():
 '''測試cplxmap函數(shù)'''
 z = cplxgrid(30)
 w1 = z
 w2 = z**3
 w3 = (z**4-1)**(1/4)
 w4 = 1/z
 w5 = np.arctan(2*z)
 w6 = np.sqrt(z)
 w = [w1,w2,w3,w4,w5,w6]
 for i in w:
 cplxmap(z,i)

def _test_cplxroot():
 '''測試cplxroot函數(shù)'''
 cplxroot(n=2)
 cplxroot(n=3)
 cplxroot(n=4)
 cplxroot(n=5)

if __name__ == '__main__':
 _test_cplxmap()
 _test_cplxroot()

以上這篇python/Matplotlib繪制復(fù)變函數(shù)圖像教程就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持腳本之家。

相關(guān)文章

  • 深入理解Python裝飾器

    深入理解Python裝飾器

    裝飾器(decorator)是一種高級Python語法。裝飾器可以對一個函數(shù)、方法或者類進(jìn)行加工。這篇文章主要介紹了深入理解Python裝飾器的相關(guān)資料,需要的朋友可以參考下
    2016-07-07
  • 6個實用的Python自動化腳本詳解

    6個實用的Python自動化腳本詳解

    每天你都可能會執(zhí)行許多重復(fù)的任務(wù),例如閱讀 pdf、播放音樂、查看天氣、打開書簽、清理文件夾等等,使用自動化腳本,就無需手動一次又一次地完成這些任務(wù),非常方便。快跟隨小編一起試一試吧
    2022-01-01
  • Python pandas自定義函數(shù)的使用方法示例

    Python pandas自定義函數(shù)的使用方法示例

    這篇文章主要介紹了Python pandas自定義函數(shù)的使用方法,結(jié)合實例形式分析了pandas模塊相關(guān)自定義函數(shù)數(shù)值運算操作技巧,需要的朋友可以參考下
    2019-11-11
  • Python通過DOM和SAX方式解析XML的應(yīng)用實例分享

    Python通過DOM和SAX方式解析XML的應(yīng)用實例分享

    這篇文章主要介紹了Python通過DOM和SAX方式解析XML的應(yīng)用實例分享,針對這兩種解析方式Python都有相關(guān)的模塊可供使用,需要的朋友可以參考下
    2015-11-11
  • 深入解析Python?3中Hash鍵值存儲的優(yōu)勢與應(yīng)用

    深入解析Python?3中Hash鍵值存儲的優(yōu)勢與應(yīng)用

    這篇文章主要介紹了深入解析Python?3中Hash鍵值存儲的優(yōu)勢與應(yīng)用的相關(guān)資料,需要的朋友可以參考下
    2023-11-11
  • 關(guān)于Python dict存中文字符dumps()的問題

    關(guān)于Python dict存中文字符dumps()的問題

    這篇文章主要介紹了關(guān)于Python dict存中文字符dumps()的問題,本文給大家分享問題及解決方案,給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2021-10-10
  • Python讀取環(huán)境變量的方法和自定義類分享

    Python讀取環(huán)境變量的方法和自定義類分享

    這篇文章主要介紹了Python讀取環(huán)境變量的方法和自定義類分享,本文直接給出代碼實例,需要的朋友可以參考下
    2014-11-11
  • python中os.remove()用法及注意事項

    python中os.remove()用法及注意事項

    在本篇內(nèi)容里小編給大家分享的是一篇關(guān)于python中os.remove()用法及注意事項,有需要的朋友們可以跟著學(xué)習(xí)下。
    2021-01-01
  • python多進(jìn)程間通信代碼實例

    python多進(jìn)程間通信代碼實例

    這篇文章主要介紹了python多進(jìn)程間通信代碼實例,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下
    2019-09-09
  • 淺析Flask如何使用日志功能

    淺析Flask如何使用日志功能

    這篇文章主要為大家詳細(xì)介紹了Flask是如何使用日志功能的,文中的示例代碼講解詳細(xì),對我們深入了解Flask有一定的幫助,需要的可以參考一下
    2023-05-05

最新評論