Skip to content

Latest commit

 

History

4 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Standing Waves

A small Haskell simulation of travelling and standing waves, originally written for fun to share with my high-school physics class in 2022.

The simulation models the motion of particles in a medium and visualises both transverse and longitudinal waves using Reanimate.

Standing waves simulation

Status

Archived project originally written in 2022 while learning Haskell and exploring mathematical and physical simulation.

Physics

A travelling wave is modelled as

$$ y(x,t) = A\sin\left(2\pi ft - \frac{2\pi x}{\lambda}\right), $$

where $A$ is the amplitude, $f$ is the frequency and $\lambda$ is the wavelength.

Standing waves are produced by superposing two waves travelling in opposite directions:

$$y_{\mathrm{standing}}(x,t) = y(x,t) + y(-x,t).$$

The simulation also models waves travelling inwards from both ends of the container. Both transverse and longitudinal waves are represented.

Implementation

The project separates the physical model from the visualisation.

Physics

Physics.hs defines functions for:

  • travelling transverse and longitudinal waves;
  • standing transverse and longitudinal waves, obtained by superposition;
  • waves propagating from both ends of the container.

Each wave is represented as a collection of particles whose positions are determined as functions of time.

Simulation

Simulation.hs converts the particle representation into SVG graphics using Reanimate. Particles are rendered as circles, with separate visualisations for transverse and longitudinal motion.

The animation is 25 seconds long and displays the wave motion over time.

Data representation

Waves are represented using:

data Particle = Particle !Double !Double

data Wave
    = Transverse   ![Particle]
    | Longitudinal ![[Particle]]

A transverse wave is represented by a one-dimensional collection of particles, while a longitudinal wave is represented by particles arranged in columns.

Parameters

The simulation uses fixed parameters for the amplitude, frequency, wavelength and particle spacing. The current values are defined in Constants.hs.

For example:

  • wavelength: 1.5
  • amplitude: 0.125
  • frequency: 0.5
  • container length: 15

Running

This project was originally written using GHC 8.10.7 and an older version of Reanimate.

With the pinned dependencies in cabal.project.freeze, generate a GIF with:

cabal run standing-waves -- render --format gif -o <filename>.gif

See the Reanimate documentation for a complete list of rendering options.

About

Simulation and visualisation of transverse and longitudinal standing waves in Haskell

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages