-
Notifications
You must be signed in to change notification settings - Fork 2
/
example_chaoticsys.m
217 lines (168 loc) · 6.43 KB
/
example_chaoticsys.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
%% Complete and functional observability of nonlinear systems.
% This code evaluates the complete and functional observability of several
% dynamical nonlinear systems f(x), considering a measurement function h(x)
% and a functional g(x) sought to be reocnstructed.
% Calculations are based on symbolic computation using Lie derivatives.
% Arthur Montanari, 06/2022
% If you use this code, please reference:
% A. N. Montanari, L. Freitas, D. Proverbio, J. Gonçalves.
% Functional observability and subspace reconstruction in nonlinear
% systems. Physical Review Research, 4:043195 (2022).
clear all; close all; clc;
addpath([pwd,'/Systems/'])
% The following nonlinear systems were implemented:
% - rossler
% - lorenz63
% - cord
% - neuronHR
nonlinearsys = 'lorenz63'
% Simulation time
dt = 1e-2;
t0 = 0;
tf = 1010;
trans = 1000; % transiente time
st = 1e-2; % sampling time
N = length(trans/dt:round(st/dt):tf/dt); % data points
%% Nonlinear system
if contains(nonlinearsys, 'rossler')
%% ==================== ROSSLER SYSTEM ==================== %%
% System dimension
n = 3;
% Parameters (spiral a = 0.398, screw a = 0.450)
a = 0.398; b = 2; c = 4;
% Numerical simulation
s0 = randn(1,n);
[taux,saux] = odeRK(@(t,s)rossler(t,s,a,b,c),[t0 dt tf],s0);
% Remove transient, samples data
t = taux(trans/dt:round(st/dt):end);
s = saux(trans/dt:round(st/dt):end,:);
% Symbolic functions
X = sym('x',[1 n],'real')';
% Nonlinear system function
f = [- X(2) - X(3);
X(1) + a*X(2);
b + X(3)*(X(1)-c)];
% Observation function
h = X(3);
% Estimation function
g = atan(X(2)/X(1));
elseif contains(nonlinearsys, 'lorenz63')
%% ==================== LORENZ SYSTEM ==================== %%
% System dimension
n = 3;
% Parameters
sigma = 10; rho = 28; beta = 8/3;
% Numerical simulation
s0 = 0.1*randn(1,n);
[taux,saux] = odeRK(@(t,s)lorenz(t,s,sigma,rho,beta),[t0 dt tf],s0);
% Remove transient, samples data
t = taux(trans/dt:round(st/dt):tf/dt);
s = saux(trans/dt:round(st/dt):tf/dt,:);
% Symbolic functions
X = sym('x',[1 n],'real')';
% Nonlinear system function
f = [sigma*(X(2) - X(1));
rho*X(1) - X(2) - X(1)*X(3);
X(1)*X(2) - beta*X(3)];
% Observation function
h = X(1);
% Estimation function
g = X(2);
elseif contains(nonlinearsys, 'cord')
%% ==================== CORD SYSTEM ==================== %%
% System dimension
n = 3;
% Parameters
a = 0.258; b = 4.033; Fp = 8; G = 1; order = 1;
% Numerical simulation
s0 = 0.1*randn(1,n);
[taux,saux] = odeRK(@(t,s)cord(t,s,a,b,Fp,G,order),[t0 dt tf],s0);
% Remove transient, samples data
t = taux(trans/dt:round(st/dt):tf/dt);
s = saux(trans/dt:round(st/dt):tf/dt,:);
% Symbolic functions
X = sym('x',[1 n],'real')';
% Nonlinear system function
f = [-X(2)^order - X(3)^order - a*X(1) + a*Fp;
X(1)*X(2) - b*X(1)*X(3) - X(2) + G;
b*X(1)*X(2) + X(1)*X(3) - X(3)];
% Observation function
h = X(2);
% Estimation function
g = atan(X(3)/X(2));
elseif contains(nonlinearsys, 'neuronHR')
%% ==================== HINDMARSH-ROSE NEURON ==================== %%
% System dimension
n = 3;
% Parameters
a = 1; b = 3; c = 1; d = 5;
I = 3.25; r = 0.001; sdyn = 4; xR = -(1+sqrt(5))/2;%-8/5;
% Numerical simulation
s0 = 0.3 + (0.7-0.3).*rand(1,3); % s0 = randn(3,1);
[taux,saux] = odeRK(@(t,s)neuronHR(t,s,a,b,c,d,I,r,sdyn,xR),[t0 dt tf],s0);
% Remove transient, samples data
t = taux(trans/dt:round(st/dt):tf/dt);
s = saux(trans/dt:round(st/dt):tf/dt,:);
% Symbolic functions
X = sym('x',[1 n],'real')';
% Nonlinear system function
f = [X(2) - a*X(1)^3 + b*X(1)^2 + I - X(3);
c - d*X(1)^2 - X(2);
r*(sdyn*(X(1)-xR) - X(3))];
% Observation function
h = X(2);
% Estimation function
g = X(1);
end
%% Observability matrices
% Computes observability matrix
[Oc, Lieh] = nonlinearobsvmatrix(X,f,h,n-1);
Dg = simplify( jacobian(g,X) );
% Coefficient of (functional) observability
kappaPhi = zeros(N,1);
kappaPsi = zeros(N,1);
Lieh_x = zeros(N,n);
for k = 1:N
if mod(k,100) == 0; disp(['Counting ',num2str(k),'/',num2str(N)]); end
% Computes numerical values at time k
xvec = s(k,:)'; % state vector at time k
Oc_x = double(subs(Oc,X,xvec)); % obsv. matrix at time k
Phi_x = inv(Oc_x); % map Phi at k
Dg_x = double(subs(Dg,X,xvec)); % gradient of g(x) at time k
Psi_x = Dg_x*Phi_x; % map Psi at time k
% Computes Lie derivatives (differential embedding) at time k
Lieh_x(k,:) = double(subs(Lieh,X,s(k,:)'));
% Computes condition number
normp = 2;
kappaPhi(k) = norm(Phi_x,normp);
kappaPsi(k) = norm(Psi_x,normp);
end
%% Coefficients of observability
disp([' '])
disp(['Nonlinear system: ', nonlinearsys])
disp(['Measurement function:']); h
disp(['Functional:']); g
disp(['Observability matrix:']); Oc
disp(['Coefficient of complete observability (average): ', num2str(mean(kappaPhi))])
disp(['Coefficient of functional observability (average): ', num2str(mean(kappaPsi))])
%% Plots
% Original state space and embedding space
figure(1);
subplot(121); plot3(s(:,1),s(:,2),s(:,3));
xlabel('x_1'); ylabel('x_2'), zlabel('x_3');
subplot(122); plot3(Lieh_x(:,1),Lieh_x(:,2),Lieh_x(:,3));
xlabel('y'); ylabel('ydot'), zlabel('yddot');
% Coefficients of observability
figure(2)
sample = 1; dotsize = 20;
colormap((pink))
subplot(121); scatter3(s(1:sample:end,1),s(1:sample:end,2),s(1:sample:end,3),...
dotsize,kappaPhi(1:sample:end),'o','filled')
colorbar; set(gca,'ColorScale','log');
caxis([min([kappaPhi; kappaPsi]) max([kappaPhi; kappaPsi])]);
xlabel('x_1'); ylabel('x_2'), zlabel('x_3');
subplot(122); scatter3(s(1:sample:end,1),s(1:sample:end,2),s(1:sample:end,3),...
dotsize,kappaPsi(1:sample:end),'o','filled')
colorbar; set(gca,'ColorScale','log');
caxis([min([kappaPhi; kappaPsi]) max([kappaPhi; kappaPsi])]);
xlabel('x_1'); ylabel('x_2'), zlabel('x_3');