Lennard-Jones simulation of particle interaction (2D and 3D)

Investigation of the interaction of particles at different temperatures, volumes, and/or gravitational accelerations. Possible to make video
408 Downloads
Updated 9 Sep 2023

View License

This program simulates particles interacting with a Lennard-Jones potential in 2D or 3D. Change the parameters to achieve different results. You can simulate gravity and temperature gradients and compress the particles. The temperature is integrated with a Berendsen type thermostat.
In the 2D version you can increase the perfomance by suprresing the diagnostic data. Set "Perfomance_Mode" to 1. In 3D there is no diagnostic data plotting
You can color the particles according to speed, ammount of neighbours, or by position. Insert desired vector into colormap function. For better 3D immersion use the Position vector as input to help with the 3D.
You can save a video of your simulations. Watch your RAM if you want to capture long simulations!
Watch 3D Demo: https://www.youtube.com/watch?v=hyXtSrveXgM
Watch 2D Demo: https://www.youtube.com/watch?v=kM1RIdsEv7s
Note: This is a hobby project of mine and is meant for entertainment and to be expanded for personal use.

Cite As

Basil Imoberdorf (2024). Lennard-Jones simulation of particle interaction (2D and 3D) (https://www.mathworks.com/matlabcentral/fileexchange/107005-lennard-jones-simulation-of-particle-interaction-2d-and-3d), MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R2023a
Compatible with any release
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
Version Published Release Notes
2.1.0

Improved performance for 2D through reduced indexing due to splitting the variables position and velocity into two variables xPosition and yPosition

2.0.3

Performance improvements

2.0.2

YT link added

2.0.1

Added 3D version of the simulation using sphere meshes. It is not very fast with many particles but you can do the same things as in 2D like compression, gravity and temperature gradients

1.1.2

-Minor adjoustments for improved perfomance

1.1.1

-new function for temperature control
-fixed a bug in the automatic screensize generation

1.1.0

- Improved perfomance
- Figure windows now automatically adjust to the user's screen sizee
- Added new plots for kinetic energy and a molecule speed distribution histogram. Can be turned off with the new Perfomance_Mode parameter

1.0.3

Yet another forgotten file added!

1.0.2

Forgott to add the other files in Version 1.0.1. So here they are in version 1.0.2!

1.0.1

Fixed a bug in the makeMovie function!

1.0.0