Code Example

Code Example#

Let \(y = f(x)\), where \(x \in [0, 5\pi]\). Consider the following three functions:

(a) \(f(x) = \sin(x)\)
(b) \(f(x) = \sin(2x)\)
(c) \(f(x) = 2\sin(x)\)

Plot these function to better understand how frequency and amplitude affect the shape of the sine wave.

# Import necessary libraries
import numpy as np
import matplotlib.pyplot as plt
x = np.linspace(0, 5*np.pi, 100)


y = np.sin(x)
plt.plot(x, y, label='y = sin(x)')



plt.legend() # Add a legend to the plot
plt.grid(True) # Add a grid to the plot
plt.show() # Display the plot
../_images/93350a758eeb51d77c5bdc558dbbf46fdfd510cebc38987fa06f5286f6ec81d9.png