-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdiffusion_1D.m
52 lines (46 loc) · 986 Bytes
/
diffusion_1D.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
clc; clear all; close all;
%parameter
tot=10;
%initialization
dboxes1=zeros(1,tot);
dboxes2=zeros(1,tot);
boxes=randi(10,1,tot);
%evaluating differences to the right
for i=1:tot
if (i<tot)
dboxes1(i)=boxes(i+1)-boxes(i);
else
dboxes1(i)=boxes(1)-boxes(i);
end
end
%evaluating differences to the left
for i=1:tot
if(i>1)
dboxes2(i)=dboxes1(i-1);
else
dboxes2(1)=dboxes1(tot);
end
end
disp('particles')
disp(boxes)
%disp('total number')
%disp(sum(boxes)) %check: mass conservation
disp('differnces')
disp(dboxes1)
disp(dboxes2)
%particle exchangers
pexchanger1=gradino(dboxes1);
pexchanger2=gradino(dboxes2);
%summing
%for i=1:tot; %right summing
% if (i<tot)
% boxes(i)=boxes(i)+dboxes(i)+dboxes(i-1);
% boxes(i-1)=boxes(i-1)-dboxes(i);
% else
% boxes(i)=boxes(i)-dboxes(1)+dboxes(i-1);
% end
% disp(i)
%end
disp('final numbers')
disp(boxes)
disp(sum(boxes)) %check: mass conservation