How can I use ss2tf for big matrices A,B,C,D?
Ältere Kommentare anzeigen
Hello everyone,
I am trying to creat a tf from huge matrices A B C and D, the A matrice is a 250000x250000, to compute it i had to use sparse(A), the probleme is ss2tf dosnt accept sparse matrices, it gives the following error:
[nom1, denom1] = ss2tf(A,B,C,D);
Error using ss2tf (line 26)
Input matrix must be real and symmetric when matrix is sparse. Use eigs to compute a subset of
eigenvectors and eigenvalues of a sparse matrix.
full(A) couldnt work because of the size of A.
Ill be thankfull if somone shares a solution or an alternative to go throught this probleme.
Antworten (1)
Hi! I encountered the same issue where “ss2tf” expected a dense matrix but got a sparse one instead. It can be addressed by reducing the dimensionality of the system using "eigs" and constructing a reduced state-space model.
The “eigs” function extracts a subset of important eigenvalues and eigenvectors, allowing a reduced representation of the state-space model. Here's an example code to use "eigs" function:
load variable_used.mat %Load example variables used
numModes = 100; % Adjust based on your system's dynamics
% Extract a reduced model using eigs
[V, D_eigs] = eigs(A, numModes); % V: eigenvectors, D_eigs: eigenvalues (diagonal matrix)
% Reduce the state-space matrices
A_red = V' * A * V; % Project A onto the reduced subspace
B_red = V' * B; % Transform B to the reduced subspace
C_red = C * V; % Transform C to the reduced subspace
% Adjust D to match C_red's rows and B_red's columns
if size(C_red, 1) > size(D, 1)
D_red = repmat(D, size(C_red, 1), 1);
else
D_red = D(1:size(C_red, 1), :);
end
if size(B_red, 2) > size(D_red, 2)
D_red = [D_red, zeros(size(C_red, 1), size(B_red, 2) - size(D_red, 2))];
else
D_red = D_red(:, 1:size(B_red, 2));
end
% Use the reduced state-space model with ss2tf
input_index = 1; % Choose the desired input index (1 ≤ input_index ≤ number of inputs in B_red)
[nom, denom] = ss2tf(A_red, B_red, C_red, D_red, input_index);
% Display the result
disp('Numerator coefficients:');
disp(nom);
disp('Denominator coefficients:');
disp(denom);
This approach avoids memory issues while ensuring the system dynamics are preserved.
Some helpful reference links for the same:
Kategorien
Mehr zu Partial Differential Equation Toolbox finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!