5.1 μs
40.3 s
initCond (generic function with 1 method)
213 μs

Wave Equation

∂2y(x,t)∂t2=c2∂2y(x,t)∂x2

7.4 μs

Finite Difference

yij+1−2yij+yij−1(Δt)2=c2yi+1j−2yij+yi−1j(Δx)2

Let α=(cΔtΔx)2 ;

yij+1=[αyi+1j+2(1−α)yij+αyi−1j]−yij−1

10.0 μs

Matrix form

y→j+1=M⋅y→j−y→j−1

M=(2(1−α)α0....α2(1−α)α0...0α2(1−α)α0..................0α2(1−α)α0...0α2(1−α)α....0α2(1−α))

18.0 μs

Single string

20.3 μs
  • n :: Number of points in discrete spatial grid

  • xi :: Initial co-ordinate value in grid

  • xf :: Final co-ordinate value in grid

  • m :: Number of timesteps

  • dt :: Size of each time step

  • c :: Speed of wave in string

11.3 μs
waveEquation (generic function with 1 method)
197 μs

This code was written hastily, so it does not elegantly accomodate initial/boundary conditions and source terms.

You can however uncomment the specific lines above and run the function call below manually to switch between them.

29.7 μs
33.5 s

Composite string

60.4 μs
  • n :: Number of points in discrete spatial grid

  • xi :: Initial co-ordinate value in grid

  • xf :: Final co-ordinate value in grid

  • m :: Number of timesteps

  • dt :: Size of each time step

  • c1 :: Speed of wave in string 1

  • c2 :: Speed of wave in string 2

6.4 μs
waveEquationComposite (generic function with 1 method)
247 μs
9.9 s