MATLAB code¶
1D_wave_equation is a MATLAB code for the dynamics of a 1-dimensional wave equation. The trapezoidal quadrature rule is used to approximate the integral of the Lagrangian function in both time and space. Symbolic differentiation is used for the derivation of the equations and this leads to long time running. Matlab Symbolic Math Toolbox is needed.
wave_equation¶
wave_equation module contains the source code :
- wave_equation.main()¶
Variational formulation of the 1D wave equation.
- Parameters:
dtu_t0 (
u_t0,) – initial conditionsu_sl (
u_s0,) – boundary conditionsk_pot (
l, rho,) – string length, density and stiffness
- Returns:
discrete transverse deformations u
- Postprocessing:
HH energy density, PP momentum density and HH_error error in time of the energy charge
The discrete Lagrangian is defined in:
- wave_equation.discreteLag(L, delta_s, delta_t, dsu, dtu)¶
Discretisation of the Lagrangian: the trapezoidal quadrature rule is used in time and space.
- Parameters:
L – Lagrangian function
delta_s,delta_t – space and time steps
dsu,dtu – derivative of u respect to space and time
- Returns:
Ld_ij discrete Lagrangian at each node of the space-time grid
The discrete Euler-Lagrange equations are solved in time and space in:
- wave_equation.timesolver(uu_ij1_DEL, u_ij, u_i0j, u_i1j, u_ij0, uu, n_t, n_s)¶
Time solver of the discrete Euler-Lagrange equations.
- Parameters:
u_ij – discrete transverse deformations
n_t,n_s – number of time and space steps
- Returns:
uu discrete transverse deformations at the interior points of the space-time grid (solution of the discrete Euler-Lagrange equations)
The conjugate momenta in time is evaluated in:
- wave_equation.eval_ppt(Ld_ij, Ld_i0j, Ld_ij0, Ld_i0j0, u_ij, u_i0j, u_i1j, u_ij1, u_ij0, uu, delta_s, n_t, n_s)¶
Legendre transform.
- Parameters:
u_ij – discrete transverse deformations over the space-time grid, space and time steps
Ld_ij – discrete Lagrangians over the space-time grid
delta_t,n_t,n_s – time step size, and number of time and space steps
- Returns:
pp_t canonical momenta w.r.t. time evaluated at each node of the space-time grid
The conjugate momenta in space is evaluated in:
- wave_equation.eval_pps(Ld_ij, Ld_i0j, Ld_ij0, Ld_i0j0, u_ij, u_ij1, u_ij0, u_i1j1, u_i1j, u_i0j, u_i0j1, uu, delta_t, n_t, n_s)¶
Legendre transform.
- Parameters:
u_ij – discrete transverse deformations over the space-time grid, space and time steps
Ld_ij – discrete Lagrangians over the space-time grid
delta_t,n_t,n_s – time step size, and number of time and space steps
- Returns:
pp_s canonical momenta w.r.t. space evaluated at each node of the space-time grid