以下是绘制Weierstrass函数分形图的Python代码:

import matplotlib.pyplot as plt
import numpy as np

def weierstrass(x, a, b):
    """
    Weierstrass function
    """
    return np.sum([a**n * np.cos(b**n * np.pi * x) for n in range(100)])

# Define domain
x = np.linspace(-2, 2, 10000)

# Define function parameters
a = 0.5
b = 3

# Evaluate function
y = [weierstrass(xi, a, b) for xi in x]

# Plot function
plt.plot(x, y)

# Add labels and title
plt.xlabel("x")
plt.ylabel("y")
plt.title("Weierstrass Function")

# Show plot
plt.show()

这段代码会绘制Weierstrass函数的图像,并且可以通过修改ab参数来改变函数的形状

帮我找绘制Weierstrass函数分形图的python代码

原文地址: http://www.cveoy.top/t/topic/hoyo 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录