You are on page 1of 9

UNIVERSITAS INDONESIA

KIMIA KOMPUTASI (B)

TUGAS PEMBELAJARAN MATHLAB

Dosen : Devvi Sarwinda S.Si, M.Kom

ZEVANO C. SIBARANI

(1506740654)

DEPARTEMEN KIMIA
FAKULTAS MATEMATIKA DAN ILMU PENGETAHUAN ALAM
UNIVERSITAS INDONESIA
2018
➢ Gambar grafik simulasi 1-3
➢ Gambar tugas grafik
➢ Gambar tugas grafik dengan pemberian warna merah (red)
➢ Model perumusan dari simulasi
Parameter konfigurasi
mass = 0.5;
dt = 0.001;
dt2 = dt*dt;
dwPar = 1;

parameter simulasi
nSteps = 1000000;
sampleFreq = 1;
sampleCounter = 1;

rumus lintasan posisi dan kecepatan


xTraj = zeros(1,nSteps/sampleFreq);
vTraj = zeros(1,nSteps/sampleFreq);

kondisi awal
x = 0;
oldX = 0.5;

dinamika molekular
Menghitung posisi baru dari persamaan gerak
𝑓(𝑡)
𝑥(𝑡−𝑑𝑡) = 2𝑥𝑡 − 𝑥(𝑡−𝑑𝑡) + 𝑑𝑡 2 ( ) + 𝑂(𝑑𝑡 4 )
𝑚𝑎𝑠𝑠𝑎
𝑑𝑡 2 𝐹𝑜𝑟𝑐𝑒(𝑥,𝑑𝑤𝑃𝑎𝑟)
𝑥 = 2𝑥 − 𝑜𝑙𝑑𝑋 +
𝑚𝑎𝑠𝑠𝑎

Dimana,
Jika x < 0 ; Maka: 𝐹𝑜𝑟𝑐𝑒 = −2 × 𝑟𝑝𝑚 × (𝑥 + 1)
Jika x > 0 ; Maka: 𝐹𝑜𝑟𝑐𝑒 = −2 × 𝑟𝑝𝑚 × (𝑥 − 1)

oldX = x(t) dan x = x(t+dt)


Maka, oldX = tmp

Hasil integrasi kecepatan (v)


(𝑥(𝑡+𝑑𝑡) −𝑥(𝑡) )
𝑣(𝑡+𝑑𝑡) = 𝑑𝑡+𝑂(𝑑𝑡)
(𝑥−𝑜𝑙𝑑𝑋)
𝑣= 𝑑𝑡
Dimana O(dt) adalah persamaan Verlet

Sampel
Lintasan x = x
Lintasan v = v
sampleCounter = sampleCounter + 1

Hasil Perhitungan
Gambar 1
Sumbu x = Waktu
Sumbu y = Posisi (lintasan x)

Gambar 2
Sumbu x = Waktu
Sumbu y = Total energy

Total energy = energi kinetik + energy potensial


1
𝐸𝑛𝑒𝑟𝑔𝑖 𝑘𝑖𝑛𝑒𝑡𝑖𝑘 = 𝑚 (𝑙𝑖𝑛𝑡𝑎𝑠𝑎𝑛 𝑣)2
2

Energi potensial = uEnergi(Lintasan x, dwPar)


Dimana uEnergi
Ketika
𝐸𝑛𝑒𝑟𝑔𝑖 (𝑥 < 0) = 𝑝𝑟𝑚 𝑥 (𝑥 − 1)(𝑥 − 1)
𝐸𝑛𝑒𝑟𝑔𝑖 (𝑥 > 0) = 𝑝𝑟𝑚 𝑥 (𝑥 + 1)(𝑥 + 1)
➢ Model perumusan dari tugas grafik
✓ Script Tugas 1
clear all; close all;

% Set configuration parameters


mass = 0.5; % Particle mass
dt = 0.001; % Integration time
dt2 = dt*dt; % Integration time, squared
dwPar = 1; % A parameter to scale the double well potential

% Set simulation parameters


nSteps = 1000000; % Total simulation time (in integration steps)
sampleFreq = 1; % Sampling frequency
sampleCounter = 1; % Sampling counter

% Set trajectories to follow particle's position and velocity


xTraj = zeros(1,nSteps/sampleFreq);
vTraj = zeros(1,nSteps/sampleFreq);

% Set initial conditions


x = 0; % Initial position
oldX = -0.005; % Position in previous time step

% ===================
% Molecular Dynamics
% ===================
for step = 1:nSteps

% Tmp will hold x(t)


tmp = x;

% Calculate the new x positon by integrating the equations of


motion
% x(t+dt) = 2*x(t) - x(t-dt) + dt^2*(f(t)/m) + O(dt^4)
x = 2.0*x - oldX + Force(x,dwPar)*dt2/mass;
% oldX now holds x(t), and x holds x(t+dt)
oldX = tmp;

% Integrate the velocity as well.


% O(dt) accurate. See Verlet integration on wikipedia
% v(t+dt) = (x(t+dt) - x(t))/ dt + O(dt)
v = (x - oldX)/dt;

% Sample
if mod(step,sampleFreq) == 0
xTraj(sampleCounter) = x;
vTraj(sampleCounter) = v;
sampleCounter = sampleCounter + 1;
end
end

% ===================
% Simulation results
% ===================

% Plot the particle's position trajectory


figure(1)
plot(xTraj, 'r.');
xlabel('time')
ylabel('Position')

% Plot the sum of kinteic and potential energy - to check for


conservation
figure(2)
potEnergy = uEnergy(xTraj,dwPar);
kinEnergy = 0.5*mass*(vTraj.^2);
plot(potEnergy + kinEnergy, 'r.' );
xlabel('time')
ylabel('Total Energy')

✓ Script Force
function force = Force(x,prm)
% The derivative is different for negative and positive positions
if x < 0
force = -2*prm*(x+1);
else
force = -2*prm*(x-1);
end
end

✓ Script uEnergi
function energy = uEnergy(x,prm)

% The potential gets different values if x is smaller or greater


than 0
right = prm*(x-1).*(x-1);
left = prm*(x+1).*(x+1);

% Calculate the energy for x of any size array


energy = zeros(size(x)); % Zero out the energy
energy(x<0) = left(x<0); % Set energy to be the 'left' array for
negative x values
energy(x>=0) = right(x>=0); % Set energy to be the 'right' array
for positive x values
end

You might also like