-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathExample_Lorenz.m
83 lines (51 loc) · 1.55 KB
/
Example_Lorenz.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
%Reconstruction of Lorenz system using ABM algorithm and delMinorTerms
rng default;
close all;
%simulate Lorenz system
Tmax = 45;
h = 0.01;
[t,y] = ode45(@Lorenz,[0:h:Tmax],[0.1,0,-0.1]); %solve ODE
w = transpose(Lorenz(0,transpose(y))); %find derivatives
%plot x-z plane projection
figure(1);
plot3(y(:,1),y(:,2),y(:,3));
xlabel('\itx');
ylabel('\ity');
zlabel('\itz');
%get uniformly distributed points from the simulated attractor
N = 19; %data points
M = 3; %dim
[Ns, ~] = size(y);
W = zeros(N,M);
Y = zeros(N,M);
for i = 1:N %take random points from attractor
id = ceil(rand*Ns); %number of data point
W(i,:) = w(id,:); %X
Y(i,:) = y(id,:); %Y
end
%plot sample points
figure(1); hold on
scatter3(Y(:,1),Y(:,2),Y(:,3),23,'MarkerEdgeColor','g','MarkerFaceColor','y','LineWidth',1.5);
%reconstruct order ideal
eps = 1e-5;
sigma = deglexord(0,2,3);
[~, O] = ApproxBM(Y, eps, sigma) %use approximate Buchberger-Moller algorithm
%Use LSM for fitting the equations with the proper coefficients
eta = 1e-7;
H = cell(1,3);
T = cell(1,3);
%reconstruct each equation
for i = 1:3
V = W(:,i);
[hi,tau] = delMinorTerms(Y,V,O,eta); %get equation and basis
V0 = EvalPoly(hi,Y,tau);
norm(V - V0) %check if norm is appropriate
H{1,i} = hi;
T{1,i} = tau;
end
%simulate results
[~,y] = ode45(@(t,x)oderecon(H,T,t,x),[0:h:Tmax],[0.1,0,-0.1]); %solve ODE
figure(1);
plot3(y(:,1),y(:,2),y(:,3),'-');
%display equations
prettyABM(H,T)