Question: MATLAB BASE CODE: clc clear all close all % n = 2 ; % mumber of particles n = 3 ; qe = - 1
MATLAB BASE CODE:
clc
clear all
close all
n ; mumber of particles
n ;
qe e; the charge of an electron
me e; mass of an electron
cell e; observing a box of cm
initial positions
Xs e; the list of particles xcordinates
Ys ; the list of particles ycordinates
Xs ee; the list of particles xcordinates
Ys e; the list of particles ycordinates
initail velocities
Us e; the list of particles xvelocity
Vs ; the list of particles yvelocity
Us e; the list of particles xvelocity
Vs ; the list of particles yvelocity
timesteps
dt e; runnig itteratins for every ps
imax edt; duration of sim: ns
ireport edt; print once every ns
create a matrix of particle paris that makes sure we dont double count
pairs triuonesn;
Force initialization
caculate the force as a sum of each particles from each particle pair
Fx zerosn;
Fy zerosn;
for i :n
for j i:n
if pairsijonly applies to unique particle pairs
dx Xsj Xsi; ditance between the electrons in x dim
dy Ysj Ysi; ditance between the electrons in y dim
r sqrt dx dy; the toltal distance magnitude between the two
electrons
R dx dyr; normalized vector for direction of the force
F FCoulombr qe qe; force between ith and jth
particle i
Fxi Fxi FR; force componets in X
Fyi Fyi FR; force componets in y
particle i
apply Newton's third law
Fxj Fxj FR; force componets in X
Fyj Fyj FR; force componets in y
end
end
end
main simulation using the verlt
for t :imax
update the position
Xs Xs Usdt Fxmedt; position update in x
Ys Ys Vsdt Fymedt; position update in y
half update velocity
Us Us Fxmedt; velocity in X
Vs Vs Fymedt; velocity in y
recalculate the force
Fx zerosn;
Fy zerosn;
for i :n
for j i:n
if pairsijonly applies to unique particle pairs
dx Xsj Xsi; ditance between the electrons in x dim
dy Ysj Ysi; ditance between the electrons in y dim
r sqrt dx dy; the toltal distance magnitude between the two
electrons
R dx dyr; normalized vector for direction of the force
F FCoulombr qe qe; force between ith and jth
particle i
Fxi Fxi FR; force componets in X
Fyi Fyi FR; force componets in y
particle i
apply Newton's third law
Fxj Fxj FR; force componets in X
Fy
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
