How to limit a function's cosine value as it approaches 0 How do I get a cosine to peak up to a certain value as it hits 0? With the above code, the y-value peaks to infinity as it approaches 0.
import matplotlib.pyplot as plt
import numpy as np

amp = 1
time = np.linspace(-5, 5, 1000)

signal = np.cos(1 * np.pi * time) * abs(1/time)

plt.figure(figsize=(10, 10))
plt.ylim(-4, 4)
plt.plot(time, signal, color=&quot;black&quot;)
plt.savefig('output.png', bbox_inches='tight', pad_inches=0,
            transparent=True)

Put another way, based on my google-fu, how can I create a symmetrical exponentially decaying sinusoid with a maximum y-value as it approaches 0?
$\alpha e^{-\beta x^2}cos(x)$ where $\alpha$ is your peak and $\beta$ is proportional to the strength of the decay
This one's slightly longer and the peak is at $\alpha+1$ but the graph is easier to manipulate:

$cos(x)e^{-\beta x^2}+\alpha e^{-x^2}$