-
Notifications
You must be signed in to change notification settings - Fork 2
/
Saturn_SlowDiscovery.m
89 lines (75 loc) · 2.42 KB
/
Saturn_SlowDiscovery.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
% ------------------------------------------------------------------
% SINDy method for discovering slow timescale dynamics
% ------------------------------------------------------------------
% Application to the motion of Saturn as governed by a 3-body system
% with the Sun, Jupiter, and Saturn. Data is restricted to the orbital
% plane and loaded from the file three_body_data.mat.
%
% This code is associated with the paper
% "Sparse Identification of Slow Timescale Dynamics" by Jason J.
% Bramburger, Daniel Dylewsky, and J. Nathan Kutz (2020).This script is
% used to obtain the results in Section IV B.
% ------------------------------------------------------------------
% Clean workspace
clear all
close all
clc
format long
% Load Saturn data
load saturn_data;
data = saturn_data;
% Initializations
n = 2; %number of components
l = length(tspan);
dt = tspan(2) - tspan(1);
T = 29.5; % Saturn fast period
sample = [1 2]; % restrict to orbital plane
count = 1;
%% Coarsened Data
for j = 1:l-1
if mod(tspan(j+1),T) == 0
xt(1:n,count) = data(sample,j);
count = count+1;
end
end
cut = 1500; % Truncate size of input data
xtnext = xt(:,2:cut)';
xt = xt(:,1:cut-1)';
%% SINDy for Slow Discovery
% Access SINDy directory
addpath Util
% pool Data (i.e., build library of nonlinear time series)
polyorder = 5; %polynomial order
usesine = 1; %use sine on (1) or off (0)
Theta = poolData(xt,n,polyorder,usesine);
% compute Sparse regression: sequential least squares
lambda = 0.001; % lambda is our sparsification knob.
% apply iterative least squares/sparse regression
Xi = sparsifyDynamics2(Theta,xtnext,lambda,n);
if n == 4
[yout, newout] = poolDataLIST({'x','y','z','w'},Xi,n,polyorder,usesine);
elseif n == 3
[yout, newout] = poolDataLIST({'x','y','z'},Xi,n,polyorder,usesine);
elseif n == 2
[yout, newout] = poolDataLIST({'x','y'},Xi,n,polyorder,usesine);
elseif n == 1
[yout, newout] = poolDataLIST({'x'},Xi,n,polyorder,usesine);
end
fprintf('SINDy model: \n ')
for k = 2:size(newout,2)
SINDy_eq = newout{1,k};
SINDy_eq = [SINDy_eq ' = '];
new = 1;
for j = 2:size(newout, 1)
if newout{j,k} ~= 0
if new == 1
SINDy_eq = [SINDy_eq num2str(newout{j,k}) newout{j,1} ];
new = 0;
else
SINDy_eq = [SINDy_eq ' + ' num2str(newout{j,k}) newout{j,1} ' '];
end
end
end
fprintf(SINDy_eq)
fprintf('\n ')
end