forked from nairaditya/Modal-Decomposition-ROM
-
Notifications
You must be signed in to change notification settings - Fork 0
/
DMD.m
70 lines (46 loc) · 1.73 KB
/
DMD.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
function [ ProjectedModes,DEv,ExactModes,Norm ] = DMD( X,Y,varargin )
% Dynamic Mode Decomposition as presented by
% "On Dynamic Mode Decomposition: theory and applications" by Tu et al.,
% 10.3934/jcd.2014.1.391
% inputs :
% Data Sets X and Y- should have the same size
% each column of X is a set of measurements done at an instant
% each column of Y is the image of the corresponding columns from X
% or
% ( X,Y,Tol ) - with Tol (optional) being the threshold for filtering thru SVD - the
% default value is 1e-10
% outputs:
% 1 - Projected Dynamic Modes
% 2 - Exact Dynamic Modes
% 3 - Dynamic Eigenvalues
% 4 - Norms - Euclidean (vector) norm of each mode, used to sort the data
% setting SVD hard threshold
if isempty(varargin)
Tol=1e-10;
else
Tol=varargin{1};
end
disp(['Tolerance used for filtering in DMD:',num2str(Tol)])
[U,S,V]=svd(X,'econ');
k = find(diag(S)>Tol,1,'last');
disp(['DMD subspace dimension:',num2str(k)])
U = U(:,1:k); V=V(:,1:k); S=S(1:k,1:k);
Atilde = ((U'*Y) *V )* diag((1./diag(S)));
[W,DEv]=eig(Atilde);
DEv = diag(DEv);
ProjectedModes = U*W;
ExactModes = bsxfun(@times,1./DEv.',((Y*V)*S^(-1))*W);
if nargout>3
b = pinv(ProjectedModes)*X(:,end); % terminal coordinates in the Koopman subspace
[Norm,Index]=sort(abs(b),'descend');
DEv = DEv(Index);
ProjectedModes = ProjectedModes(:,Index);
disp('modes sorted based on energy contribution to the last snapshot')
end
end
%=========================================================================%
% Hassan Arbabi - 08-17-2015
% Mezic research group
% UC Santa Barbara
%=========================================================================%