Molecular Dynamics problem

I'm trying to do this question and I can not figure out how to.


Molecular dynamics is a computer simulation method for studying the physical movements
of atoms and molecules. Write a C script that simulates N number of particles where N is
input by the user. Define and use a structure containing the following variables:
• positions (q)
• velocities ( ˙q)
• kinetic energy (T)
• potential energy (Φ)
Note that each body has three positions, three velocities, a scalar kinetic energy, and a scalar
potential energy.

1)Assuming a cubic simulation volume of (100 × 100 × 100) with center at (0,0,0), randomly generate floating numbers for the particle positions (q).

2)Randomly generate particle velocities (q˙) where the velocity magnitude is constrained by:
x^2 + y^2 + z^2 ≤ 200

3) Using the generated velocities, calculate and print the total kinetic energy of the system.
Assuming the particles do not rotate, the total kinetic energy is given by:
Ttotal =N
Sum (m/2) (x^2 + y^2 + z^2)
i=1
You may assume the particles are all of the same material and have a unit mass of 1.

4. Using the generated positions, calculate and print the total potential energy of the system.
An easily implemented (but not the most efficient) way of calculating this energy is:
Φtotal =.5Ni=1Φi
where Φi
is the potential energy of the i
th particle. This quantity is calculated by considering
all of the potential interactions the i
th particle has with every other particle:
Φij = A - B + C
----- ------ -----
(dij)^12 (dij)^6 (dij)

Φi =N
SUM Φij
j=1

where dij is the distance between the i
th and j
th particle and A, B, and C are constants.
Use A=5, B=10, C=100.

This is what i have for number 1, which appears to work.
#include <cstdlib>
#include <iostream>

int main(){
int N , x, y, z;
printf("Enter the number of particles: \n");
scanf("%d", &N);
random [N];
printf("The position of the particles are\nx: y: z:\n");
srand(time(NULL));
for(int i = 0; i <= N; i++){


int x = rand() % 100;
int y = rand() % 100;
int z = rand() % 100;


printf("%d %d %d\n", x, y, z);

}
return 0;
}

This is what I have for number two, which i cant figure out how to limit the random x,y,z velocities to the magnitude of 200(equation above). I also have no idea what to do for number 3 and 4.
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <ctime>
using namespace std;

int main(){
int N , x, y, z, vt;
cout << "Enter the number of particles: \n";
cin >> N;
cout << "The velocity of the particles are\nx: y: z:\n";
std::srand(time(NULL));
for(int i = 1; i <= N; i++){

int x = std::rand() % 200;
int y = std::rand() % 200;
int z = std::rand() % 200;

cout << x; y; z;

}
}
Topic archived. No new replies allowed.