Showing posts with label Matlab code. Show all posts
Showing posts with label Matlab code. Show all posts

Monday, March 31, 2014

Matlab and C codes for a single harmonic oscillator coupled with a Nose-Hoover thermostat

A single harmonic oscillator represents a very useful case for understanding the principles of non-equilibrium statistical mechanics. Today, I finished coding in Matlab and in C. The matlab files and C file can be downloaded from the following links:
Matlab Files:
nh.m
main.m
C File:
nh.c
For running matlab file download both nh.m and main.m in the same folder and then run main.m. Matlab uses ODE45 solver, which is not that great!
Standard 4th order Runge Kutta solver is used in nh.c. Output is stored in the file hh.dat. On Linux based systems run the following commands:
1. gcc nh.c -lm -g
2. ./a.out

If you find any mistake in the code, let me know. And if you like this code, drop a message :-). In case of any queries, again drop a message. I would be happy to resolve queries.

Molecular Dynamics Simulation Code in MATLAB

While I started working on Molecular Dynamics, I wanted to take a look at a sample code. But, I could not find any code especially in MATLAB. For those who need the molecular dynamics code in MATLAB, download the attached files. Codes utilize reduced units and takes into account pairwise Lennard-Jones interaction

main.m is the main file which contains all the details about other functions
initialize.m is a function  which initializes all the variables
eval_force.m is a function for calculating force
integrate.m is a function for calculating the update position and velocities
print_init.m is a function to print initial datasets
print_traj.m is used for printing the trajectories (in LAMMPS format) which can be viewed using VMD
visualize.m is used instant visualization of results

Download link is attached below:
Molecular_Dynamics_Matlab_Lennard_Jones