-
Notifications
You must be signed in to change notification settings - Fork 0
/
assignment3.m
134 lines (116 loc) · 2.44 KB
/
assignment3.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
clear;
clc;
T = 300;
m0=9.11*10^-31; %in kg
mn=0.26*m0;
kB=1.38*10^-23;
vth=sqrt(2*kB*T/mn);%thermal velocity
deltaV=0.1;
W=1*10^-7;
L=2*10^-7;
E=deltaV/L; %Question 1 (a)
q=1.6*10^-19;
F=q*E; %Question 1 (b)
a=F/mn; %Question 1 (c)
N=20; %number of particles
deltaT=5*10^-15;
tTotal=1000*deltaT;
tmn=0.2*10^-12;
n=10^15;%electron concentration
%Initial velocity
vx=zeros(1,N);
vy=zeros(1,N);
%Initial position of each particles
xPos=zeros(1,N);
yPos=zeros(1,N);
for i = 1:N
x=rand*L;
y=rand*W;
xPos(i)=xPos(i)+x;
yPos(i)=yPos(i)+y;
vx(i) = vth/sqrt(2)*randn;
vy(i) = vth/sqrt(2)*randn;
end
for t = 0 : deltaT : tTotal
for i=1:N
P = 1-exp(-deltaT/tmn);
if P > rand()
vx(i) = vth/sqrt(2)*randn;
vy(i) = vth/sqrt(2)*randn;
end
end
deltaPx = vx*deltaT+(1/2)*a*deltaT^2;
deltaPy = vy*deltaT;
for i=1:N
if yPos(i)+deltaPy(i)>W||yPos(i)+deltaPy(i)<0
vy(i)=-vy(i);
deltaPy(i)=vy(i)*deltaT;
end
end
xPos=xPos+deltaPx;
yPos=yPos+deltaPy;
vxAvg=mean(vx);
j=n*q*vxAvg;
I=j*W
figure(1);
plot(t,I,'.');
xlim([0 tTotal]);
xlabel('t');
ylabel('I');
hold on;
%Periodic boundary condition in x direction
Ix=xPos>L;
xPos(Ix)=xPos(Ix)-L;
Ix=xPos<0;
xPos(Ix)=xPos(Ix)+L;
figure(2);
plot(xPos,yPos,'.');
hold on;
xlim([0 L]);
ylim([0 W]);
KEsum=0;
for i = 1:N
v_Squared = vx(i)^2+vy(i)^2;
KEsum = KEsum + (1/2)*mn*v_Squared;
end
KEavg = KEsum /N;
T=KEavg/kB;
pause(0.001);
vx=vx+a*deltaT;
end
%Part3 question c: electron density map
P=zeros(200,100);
xPos = xPos.*10^9;
yPos = yPos.*10^9;
for i=1:N
for j = 1:200
for k = 1:100
if xPos(i) > j && xPos(i)< (j+1) && yPos(i)>k && yPos(i)<(k+1)
P(j,k) = P(j,k)+1;
end
end
end
end
figure(3);
surf(P);
title('Electron density map');
%Part3 question d: temperature map
Temp=zeros(200,100);
xPos = xPos;
yPos = yPos;
for i=1:N
for j = 1:200
for k = 1:100
if xPos(i) > j && xPos(i)< (j+1) && yPos(i)>k && yPos(i)<(k+1)
v_Squared = vx(i)^2+vy(i)^2;
T = (1/2)*mn*v_Squared/kB;
Temp(j,k) = Temp(j,k)+T;
end
end
end
KE=0;
end
figure(4);
surf(Temp);
title('Temperature map');
hold off;