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

Wave Equation

2y(x,t)t2=c22y(x,t)x2

7.4 μs

Finite Difference

yij+12yij+yij1(Δt)2=c2yi+1j2yij+yi1j(Δx)2

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

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

10.0 μs

Matrix form

yj+1=Myjyj1

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