Share
Explore BrainMass

Velocity Algorithm Code

Write the simplest possible one-dimensional "molecular dynamics code" for two particles. I used matlab, so i need matlab code for molecular dynamics or velocity verlet algorithm code. I need to determine x1, x2 and v1, v2 in different time steps.

I have the following 15 values for x1, x2 and v1,v2 in graphs:

M = 1.0
dt = 0.0001
x1(t=0)=1.0
x2(t=0)=-1.0
v1(t=0)=0.0
v2(t=0)=0.0
r=2^(1/6)=1.122
limited r=0.01
U(r=2)=4[2^(-12)-2^(-6)]<0

x1(t+1)=x1(t)+dt*v1(t)+(dt)^2*0.5*f1(t)
v1(t+1)=v1(t)+dt*[f1(t+1)+f1(t)]*0.5

x2(t+1)=x2(t)+dt*v2(t)+(dt)^2*0.5*f2(t)
v2(t+1)=v2(t)+dt*[f2(t+1)+f2(t)]*0.5

f1(t)=(x1(t)-x2(t))[48 r^(-14) - 24 r^(-8)]
f2(t)=(x2(t)-x1(t))[48 r^(-14) - 24 r^(-8)]

I need the code. Also, I need graphs that show the motion of two particles, specifically, when x1=1.0 and x1=-1.0, and another graph when v1=0.0 and v2 =0.0. Also, graph when 0.5*(v1(t)^2) + 0.5*(v2(t)^2) and 0.5*(v1(t)^2) + 0.5*(v2(t)^2)+U(r).

Solution Preview

I worked it out. The code is here below, which you simply have to run. I am fairly certain you have to find r for each new time, since it is the distance between the two particles. So, in your equations for f, it should come out as r(t).so i have done this and U(r(t)).
Run the code and you'll have the graphs.

*CODE
------------------------------------------------------------------------------------------------------------------------------------------------------------------
clear all;clc
n = 80000; %number of iterations: controls the run time every 10,000=1 second
%pre-allocating empty arrays
x1 = zeros(n,1);
x2 = x1;
v1 = x1;
v2 = v1;
f1 = x1;
f2 = f1;
r = x1;
U=r;

% Initial Conditions
dt = ...

Solution Summary

The expert writes the simplest possible one-dimensional "molecular dynamics code" for two particles. The matlab code for molecular dynamics or velocity verlet algorithms code are determined.

$2.19