-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.m~
65 lines (51 loc) · 901 Bytes
/
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
clear variables
%% PARAMETERS:
%number of agents
N=3;
%dimension
d=2;
%final time
T=1;
%mesh length
n=10;
%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 = 10;
[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] = call_osc(x0, 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 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