-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.m
74 lines (59 loc) · 1.02 KB
/
main.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
clear variables
%% PARAMETERS:
%number of agents
N=10;
%dimension
d=2;
%final time
T=0.5;
%mesh length
n=100;
%mesh size
h=T/(n-1);
%mesh
t=0:h:T;
%adjacency matrix
w = define_w(N);
%% INITIAL CONDITION
x0 = zeros(N, d);
% N points evenly spaced on a circle of radius r
r = 5;
[x1, x2] = Init(N, r);
x0(:, 1) = x1;
x0(:, 2) = x2;
% N points in a row
% x0(1,1) = 0;
% for i = 2:N
% %x0(i,2)=0;
% x0(i,1) = x0(i-1,1) + 2;
% end
plot(x1, x2, '*');
hold all
%% SOLVE EQUATION
%sol = EulerMethod(x0, w, N, d, n, h);
sol = BackEulerMethod(x0, w, N, d, n, h);
%[t, sol] = MATLABsolver(x0, w, T, N, d);
%% PLOT TRAJECTORIES
%figure
nn = length(sol(1,1,:));
%nn=n;
for i=1:N
plot(reshape(sol(i,1,:), nn, 1), reshape(sol(i,2,:), nn, 1));
hold all
end
%% PLOT shift 1 against ime
figure
nn = length(sol(1,1,:));
%nn=n;
for i=1:N
plot(t, reshape(sol(i,1,:), nn, 1));
hold all
end
%% PLOT shift 2 against ime
figure
nn = length(sol(1,1,:));
%nn=n;
for i=1:N
plot(t, reshape(sol(i,2,:), nn, 1));
hold all
end