使用 Python 生成可调节参数的函数图像

使用 Python 生成可调节参数的函数图像

Can you plot the graph where I can adjust $k$? I want to know the influence of different K's on graphs.

the function:

is an exponential decay function centered at $x=10000$ . The parameter $k$ affects the rate of decay: the higher the value of $k$, the faster the function approaches zero as $x$ increases beyond 10000.

To help you visualize the influence of different $k$ values, I'll plot an interactive graph where you can adjust $k$ and see how the curve changes.

To run this code, you'll need to install matplotlib and ipywidgets if you haven't already. You can install these packages using pip:

pip install matplotlib ipywidgets numpy

Run jupyter notebook

jupyter notebook

Input:

import matplotlib.pyplot as plt
import numpy as np
import ipywidgets as widgets
%matplotlib inline

Then:

def plot_exp_decay(k):
    x = np.linspace(9500, 10500, 500)
    y = np.exp(-k * (x - 10000))

    plt.figure(figsize=(10, 6))
    plt.plot(x, y, label=f'$e^{{-{k} \cdot (x - 10000)}}$')
    plt.title("Exponential Decay Function")
    plt.xlabel("x")
    plt.ylabel("y")
    plt.legend()
    plt.grid(True)
    plt.show()

And:

k_slider = widgets.FloatSlider(value=0.001, min=0.001, max=0.1, step=0.001, description='K:')
widgets.interactive(plot_exp_decay, k=k_slider)

Output:


Create by ChatGPT-4 with Advanced Data Analysis