【问题标题】:Sine Function with an exponential amplitude with a plusminus in PythonPython中带有正负号的指数幅度的正弦函数
【发布时间】:2022-01-22 20:12:36
【问题描述】:

我想绘制这个表达式:

但我不明白如何在代码中管理时间和加减号。

我需要这样的东西(这张图片是 Simulink/Matlab 中的电压图)

【问题讨论】:

  • 从尝试获取左半部分开始。其余的只是镜像的相同曲线,在时间上移动并垂直偏移以匹配前半部分的最后一个 y 值。

标签: python numpy matplotlib math plot


【解决方案1】:

首先,你必须定义一个带有时间值的t数组:

t = np.linspace(0, 0.01, N)

然后您可以计算 Vr 作为时间的函数。您报告的表达式包含一个 ±,因此它不是数学函数:您必须为每个符号定义两个不同的函数(数组):

Vr_plus = 15000*np.exp(-2500*t)*np.sin(t)
Vr_minus = -15000*np.exp(-2500*t)*np.sin(t)

最后,你可以画出情节了:

plt.style.use('seaborn-whitegrid')
fig, ax = plt.subplots()

ax.plot(t, Vr_plus)
ax.plot(t, Vr_minus)

plt.show()

完整代码

import numpy as np
import matplotlib.pyplot as plt


N = 1000
t = np.linspace(0, 0.01, N)

Vr_plus = 15000*np.exp(-2500*t)*np.sin(t)
Vr_minus = -15000*np.exp(-2500*t)*np.sin(t)


plt.style.use('seaborn-whitegrid')
fig, ax = plt.subplots()

ax.plot(t, Vr_plus)
ax.plot(t, Vr_minus)

plt.show()

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-11-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多