How to solve the wave equation in 2D using the Runge-Kutta Method (Matlab Code Explained)
First, we express the wave equation as a system of 2 first order PDEs.
Then we discretize the spatial part of the second equation
And then we program it in Matlab
We modify Runge-Kutta integrator for Velocity and Displacement
We program the Runge-Kutta integrator in Matlab
Then we add a function that helps us update the plot as the simulation progress
From here we proceed with the following
1. Set the domain
Here we set the bounds of the domain, the number of discrete points in x and y direction, the size of a grid sell, and the mesh.
2. Compute dt to ensure stability of the solution
We use the Courant–Friedrichs–Lewy (CFL) Number, the velocity of propagation and the grid size to determine the time step size.
3. Prepare the initial condition.
The displacement is initialized to be a stationary “blob” somewhere in the domain. We define the blob to be centered at xc, yc
领英推荐
The code in matlab
4. Set function handle for the right-hand side of the pde.
We set the function handle that calls the wave equation we created earlier. This function computes the rate of change of velocity and displacement over time.
5. Initialize the plot
We plot the initial condition. Since this is a 2D problem the plot would be a 3D plot. the displacement would be along the third dimension.
6. Set function handle for plot update
We set the function that would help us update the plot as the simulation progresses. This function is pointing to the function we created earlier.
7. Start video writer.
Here we use the start the video writer (setting the name, format and frame rate of the video) that would be used to capture the sequence of event as the simulation progresses.
8. Run the simulation.
Finally, we run the simulation by solving for u and v at the next time step, then using these values as the initial, we move to the next time step until we get to the stated time for the simulation.
Below is the video created.
A Chemical engineering student.....
1 年that was helpful..thank you
Green Hydrogen | Computational fluid dynamics | Mathematical Modeling and Simulation | Numerical Analysis | MATLAB, Python, R | Publication in Academic Journals
1 年Please share any reference paper
?Eficaz || Ingeniero en electrónica ||Automatización industrial ||Programación de PLC| | Instrumentación || HMI|| Redes industriales ||Dimensionamiento de tableros eléctricos || Motion Control||
1 年Métodos numéricos