Python繪制牛奶凍曲線(高木曲線)案例
前言:
牛奶凍曲線(blancmange curve),因在1901年由高木貞治所研究,又稱高木曲線。
在單位區(qū)間內,牛奶凍函數定義為:
分形曲線的輪廓會隨著階數的增多而填充細節(jié),即對于下面的來說, N的變化會增添曲線的自相似特性
import numpy as np import matplotlib.pyplot as plt s = lambda x : np.min([x-np.floor(x), np.ceil(x)-x],0) x = np.arange(1000).reshape(-1,1)/1000 N = np.arange(30).reshape(1,-1) #2^N已經很大了,精度足夠 b = np.sum(s(2**N*x)/2**N,1) plt.plot(b) plt.show()
如圖所示:
牛奶凍曲線是一種典型的分形曲線,即隨著區(qū)間的不斷縮小,其形狀幾乎不發(fā)生什么變化,例如更改自變量的范圍,令
x = np.arange(0.25,0.5,1e-3).reshape(-1,1)
最終得到的牛奶凍曲線在觀感上是沒什么區(qū)別的。
接下來繪制一下,當區(qū)間發(fā)生變化時,牛奶凍曲線的變化過程
繪圖代碼為:
from aniDraw import * # 三角波函數 s = lambda x : min(np.ceil(x)-x, x-np.floor(x)) s = lambda x : np.min([x-np.floor(x), np.ceil(x)-x],0) x = np.arange(1000).reshape(-1,1)/1000 N = np.arange(30).reshape(1,-1) #2^N已經很大了,精度足夠 b = np.sum(s(2**N*x)/2**N,1) fig = plt.figure(figsize=(12,8)) ax = fig.add_subplot() # n為坐標軸參數 def bcFunc(n): st = 1/3 - (1/3)**n ed = 1/3 + (2/3)**n x = np.linspace(st,ed,1000).reshape(-1,1) b = np.sum(s(2**N*x)/2**N,1) return (x,b) line, = ax.plot([],[],lw=1) def animate(n): x,y = bcFunc(n) line.set_data(x,y) plt.xlim(x[0],x[-1]) plt.ylim(np.min(y),np.max(y)) return line, Ns = np.arange(1,10,0.1) ani = animation.FuncAnimation(fig, animate, Ns, interval=125, blit=False) plt.show()
到此這篇關于Python繪制牛奶凍曲線(高木曲線)案例的文章就介紹到這了,更多相關Python 牛奶凍曲線內容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!
相關文章
Keras搭建孿生神經網絡Siamese?network比較圖片相似性
這篇文章主要為大家介紹了Keras搭建孿生神經網絡Siamese?network比較圖片相似性,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪2022-05-05Python+Tkinter創(chuàng)建一個簡單的鬧鐘程序
這篇文章主要為大家詳細介紹了如何使用 Python 的 Tkinter 庫創(chuàng)建一個簡單的鬧鐘程序,它可以在指定的時間播放一個聲音來提醒你,感興趣的可以學習一下2023-04-04