How to solve the wave equation in 2D using the Runge-Kutta Method (Matlab Code Explained)

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.

No alt text provided for this image


Then we discretize the spatial part of the second equation

No alt text provided for this image

And then we program it in Matlab

No alt text provided for this image

We modify Runge-Kutta integrator for Velocity and Displacement

No alt text provided for this image

We program the Runge-Kutta integrator in Matlab

No alt text provided for this image

Then we add a function that helps us update the plot as the simulation progress

No alt text provided for this image

From here we proceed with the following

  1. Set the domain.
  2. Compute dt to ensure a stable solution.
  3. Prepare the initial condition.
  4. Set function handle for the right-hand side of the PDE.
  5. Initialize the plot.
  6. Set function handle for plot update.
  7. Start video writer.
  8. Run the simulation.

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.

No alt text provided for this image

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.

No alt text provided for this image

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

No alt text provided for this image
No alt text provided for this image

The code in matlab

No alt text provided for this image

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.

No alt text provided for this image

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.

No alt text provided for this image

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.

No alt text provided for this image

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.

No alt text provided for this image

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.

No alt text provided for this image

Below is the video created.


Suha Ewaj

A Chemical engineering student.....

1 年

that was helpful..thank you

Dania Naseer

Green Hydrogen | Computational fluid dynamics | Mathematical Modeling and Simulation | Numerical Analysis | MATLAB, Python, R | Publication in Academic Journals

1 年

Please share any reference paper

Juan Alberto Zu?iga Flores

?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

要查看或添加评论,请登录

Lateef K.的更多文章

社区洞察

其他会员也浏览了