首页 > 解决方案 > Python:如何绘制 y=cosh(x) *cos(5x)

问题描述

使用 Python 我想在我的 Jupyter Notebook 中为函数 y=cosh(x)*cos(5x) 绘制曲线。

换句话说:(x 的余弦双曲线)乘以(5x 的余弦)

我该怎么做呢?我需要导入什么?非常感谢您提前。

问候

标签: pythonplottrigonometrycurvehyperbolic-function

解决方案


指定所需的 x 值范围。您可以在 Matplotlib 之上使用 Seaborn 使其更漂亮,但这是可选的:

import seaborn as sns

import matplotlib.pyplot as plt

import numpy as np

x = np.arange(-5,5,0.1)   # start,stop,step

y= (np.cosh(x))*(np.cos(5*x) )

# set a grey background (use sns.set_theme() if seaborn version 0.11.0 or above) 
sns.set(style="darkgrid")

plt.plot(x,y)
plt.show()

在此处输入图像描述


推荐阅读