Copyright | © Frank Jung 2025 |
---|---|
License | GPL-3 |
Safe Haskell | Safe-Inferred |
Language | Haskell2010 |
HarmonicOscillation
Description
This Haskell code defines a module to simulate simple
harmonic oscillation, like
the motion of a pendulum. It does this using a State
monad to manage the
changing position and time.
Example usage
To compute the position of a harmonic oscillator:
let positions = evalState harmonic (HarmonicOscillation 0 0) take 10 positions
evalState harmonic (HarmonicOscillation 0 0)
- This runs the harmonic computation, starting with an initial state where position is 0 and time is 0.
evalState
- discards the final state and gives you just the result, which is an infinite list of positions.
take 10 positions
- Since positions is an infinite list, you use a function
like
take
to get a finite number of elements from it.
Synopsis
Documentation
data HarmonicOscillation Source #
Represents the state of a harmonic oscillator. This is a simple record that holds the state of the oscillator at any given moment: its current position and the current time.
Constructors
HarmonicOscillation | |