The provided Python code visualizes the characteristics of simple harmonic motion, a fundamental concept in physics and engineering. Simple harmonic motion is a type of periodic motion where an object oscillates back and forth around an equilibrium position, following a sinusoidal pattern.
The code demonstrates how to calculate and plot the displacement, velocity, and acceleration of an object undergoing simple harmonic motion over a specified time interval. Here's a brief overview of the code and its results:
Defining Constants and Generating Time Values:
- The code begins by setting constants such as the amplitude, frequency, and phase of the motion.
- Time values are generated using NumPy's
linspace()
function, creating a linearly spaced array of time points.
Calculating Displacement, Velocity, and Acceleration Functions:
- Functions for displacement, velocity, and acceleration are defined based on the equations of simple harmonic motion.
- Displacement is calculated as a sinusoidal function of time, while velocity and acceleration are derived by taking the derivatives of displacement.
Plotting Results:
- Matplotlib is utilized to create separate subplots for displacement, velocity, and acceleration versus time.
- Each subplot illustrates the behavior of the corresponding parameter over the specified time interval.
- Displacement is represented by a blue curve, velocity by a green curve, and acceleration by a red curve.
Interpreting Results:
- The displacement subplot shows the oscillatory motion of the object over time, with the amplitude, frequency, and phase determining its shape.
- The velocity subplot indicates how the speed of the object varies as it moves back and forth, reaching maximum values at equilibrium positions and minimum values at maximum displacement.
- The acceleration subplot reveals the rate of change of velocity, demonstrating how the object's acceleration is inversely proportional to its displacement but directed towards the equilibrium position.
Overall, this code provides a comprehensive visualization of the kinematics of simple harmonic motion, aiding in the understanding and analysis of oscillatory phenomena in various fields of science and engineering.
PROGRAM
import numpy as np import matplotlib.pyplot as plt # Define constants amplitude = 1.0 # Amplitude of the oscillation (m) frequency = 1.0 # Frequency of the oscillation (Hz) phase = np.pi/2 # Phase angle (radians) # Generate time values time = np.linspace(0, 10, 1000) # Time values from 0 to 10 seconds # Calculate displacement function for simple harmonic motion def displacement(time): return amplitude * np.sin(2 * np.pi * frequency * time + phase) # Calculate velocity function (derivative of displacement) def velocity(time): return amplitude * 2 * np.pi * frequency * np.cos(2 * np.pi * frequency * time + phase) # Calculate acceleration function (derivative of velocity) def acceleration(time): return -amplitude * (2 * np.pi * frequency)**2 * np.sin(2 * np.pi * frequency * time + phase) # Calculate displacement, velocity, and acceleration values displacement_values = displacement(time) velocity_values = velocity(time) acceleration_values = acceleration(time) # Plotting plt.figure(figsize=(12, 8)) # Displacement vs. Time plt.subplot(3, 1, 1) plt.plot(time, displacement_values, color='blue') plt.title('Displacement vs. Time') plt.xlabel('Time (s)') plt.ylabel('Displacement (m)') plt.grid(True) # Velocity vs. Time plt.subplot(3, 1, 2) plt.plot(time, velocity_values, color='green') plt.title('Velocity vs. Time') plt.xlabel('Time (s)') plt.ylabel('Velocity (m/s)') plt.grid(True) # Acceleration vs. Time plt.subplot(3, 1, 3) plt.plot(time, acceleration_values, color='red') plt.title('Acceleration vs. Time') plt.xlabel('Time (s)') plt.ylabel('Acceleration (m/s^2)') plt.grid(True) plt.tight_layout() plt.show()