how to accelate the 'for loop' command' It's not end processing !!
Mostrar comentarios más antiguos
clear all, close all, clc
%import data from excel sheet I have attached
x = x.'; %just x variable
n =5000; % number of rows
m =2726; % number of columns
index1 = 1:n;
index2 = n:n+m-1;
X = []; Xprime=[];
for ir = 1:size(x,1)
% Hankel blocks ()
c = x(ir,index1).'; r = x(ir,index2);
H = hankel(c,r).';
c = x(ir,index1+1).'; r = x(ir,index2+1);
UH= hankel(c,r).';
X=[X,H]; Xprime=[Xprime,UH];
end
%% DMD of x
dt = 1;
t=[0:1:7725];
r = 16 ;
[U, S, V] = svd(X, 'econ');
r = min(r, size(U,2));
U_r = U(:, 1:r); % truncate to rank-r
S_r = S(1:r, 1:r);
V_r = V(:, 1:r);
Atilde = U_r' * Xprime * V_r / S_r; % low-rank dynamics
[W_r, D] = eig(Atilde);
Phi = Xprime * V_r / S_r * W_r; % DMD modes
%PhiP = U_r * V_r; % Projected DMD modes
lambda = diag(D); % discrete-time eigenvalues
omega = log(lambda)/dt; % continuous-time eigenvalues
% Compute DMD mode amplitudes b
x1 = X(:, 2);
b = Phi\x1; % equal to b = pinv(Phi)*x1
% DMD reconstruction
time_dynamics = zeros(r, length(t));
for iter = 1:length(t)
time_dynamics(:,iter) = (b.*exp(omega*t(iter)));
end
Xdmd = Phi * time_dynamics;
% DMD reconstruction
rr = length(lambda) ;
T = size(X,2) ;
time_dmd = zeros(T-1,rr);
for iter = 1:T-1
for p = 1:rr
time_dmd(iter,p) = b(p)*(exp(omega(p)*t(iter)));
Xdm(:,iter,p) = real(Phi(:,p)*(b(p).*exp(omega(p)*t(iter))));
end
end
X_dmd = sum(Xdm,3) ;
2 comentarios
DGM
el 29 de Jun. de 2023
What is the size of x?
Ahmed Gharieb naga
el 30 de Jun. de 2023
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Logical en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!