How can I use ss2tf for big matrices A,B,C,D?

2 Ansichten (letzte 30 Tage)
adn Bouli
adn Bouli am 18 Mär. 2021
Beantwortet: AR am 7 Feb. 2025
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)

AR
AR am 7 Feb. 2025
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:');
Numerator coefficients:
disp(nom);
1.0e+41 * Columns 1 through 9 0.0000 + 0.0000i 0.0000 - 0.0000i 0.0000 - 0.0000i 0.0000 - 0.0000i -0.0000 - 0.0000i -0.0000 + 0.0000i 0.0000 + 0.0000i -0.0000 + 0.0000i 0.0000 + 0.0000i 0.0000 + 0.0000i -0.0000 - 0.0000i -0.0000 + 0.0000i -0.0000 + 0.0000i 0.0000 + 0.0000i 0.0000 + 0.0000i 0.0000 - 0.0000i -0.0000 - 0.0000i -0.0000 - 0.0000i 0.0000 + 0.0000i -0.0000 - 0.0000i 0.0000 + 0.0000i -0.0000 - 0.0000i -0.0000 + 0.0000i 0.0000 + 0.0000i -0.0000 - 0.0000i 0.0000 + 0.0000i -0.0000 - 0.0000i 0.0000 + 0.0000i 0.0000 - 0.0000i 0.0000 - 0.0000i 0.0000 - 0.0000i 0.0000 - 0.0000i -0.0000 - 0.0000i -0.0000 + 0.0000i 0.0000 + 0.0000i 0.0000 - 0.0000i 0.0000 + 0.0000i 0.0000 - 0.0000i 0.0000 - 0.0000i 0.0000 - 0.0000i -0.0000 - 0.0000i -0.0000 + 0.0000i 0.0000 + 0.0000i 0.0000 + 0.0000i -0.0000 - 0.0000i Columns 10 through 18 -0.0000 - 0.0000i 0.0000 + 0.0000i -0.0000 - 0.0000i 0.0000 + 0.0000i -0.0000 - 0.0000i 0.0000 + 0.0000i 0.0000 + 0.0000i 0.0000 - 0.0000i -0.0000 - 0.0000i 0.0000 + 0.0000i 0.0000 + 0.0000i -0.0000 - 0.0000i -0.0000 - 0.0000i -0.0000 + 0.0000i 0.0000 + 0.0000i -0.0000 - 0.0000i -0.0000 - 0.0000i 0.0000 + 0.0000i 0.0000 + 0.0000i -0.0000 - 0.0000i -0.0000 + 0.0000i -0.0000 + 0.0000i 0.0000 + 0.0000i -0.0000 - 0.0000i -0.0000 + 0.0000i 0.0000 + 0.0000i 0.0000 - 0.0000i -0.0000 - 0.0000i -0.0000 - 0.0000i 0.0000 + 0.0000i 0.0000 + 0.0000i -0.0000 - 0.0000i 0.0000 + 0.0000i -0.0000 - 0.0000i -0.0000 + 0.0000i 0.0000 + 0.0000i 0.0000 + 0.0000i 0.0000 - 0.0000i -0.0000 - 0.0000i -0.0000 + 0.0000i 0.0000 + 0.0000i 0.0000 - 0.0000i -0.0000 - 0.0000i -0.0000 + 0.0000i 0.0000 + 0.0000i Columns 19 through 27 0.0000 + 0.0000i -0.0000 - 0.0000i 0.0000 + 0.0000i -0.0000 - 0.0000i 0.0000 + 0.0000i -0.0000 - 0.0000i 0.0000 + 0.0000i -0.0000 - 0.0000i 0.0000 + 0.0000i -0.0000 - 0.0000i 0.0000 - 0.0000i -0.0000 - 0.0000i 0.0000 + 0.0000i 0.0000 + 0.0000i -0.0000 - 0.0000i -0.0000 + 0.0000i 0.0000 + 0.0000i -0.0000 - 0.0000i -0.0000 - 0.0000i 0.0000 + 0.0000i 0.0000 - 0.0000i -0.0000 - 0.0000i -0.0000 - 0.0000i 0.0000 + 0.0000i -0.0000 - 0.0000i 0.0000 - 0.0000i -0.0000 - 0.0000i 0.0000 - 0.0000i -0.0000 - 0.0000i 0.0000 + 0.0000i -0.0000 - 0.0000i -0.0000 - 0.0000i 0.0000 + 0.0000i 0.0000 + 0.0000i -0.0000 - 0.0000i 0.0000 + 0.0000i -0.0000 - 0.0000i -0.0000 - 0.0000i 0.0000 + 0.0000i -0.0000 - 0.0000i -0.0000 - 0.0000i -0.0000 + 0.0000i 0.0000 + 0.0000i -0.0000 - 0.0000i 0.0000 + 0.0000i Columns 28 through 36 -0.0000 - 0.0000i 0.0000 + 0.0000i -0.0000 - 0.0000i 0.0000 + 0.0000i 0.0000 + 0.0000i -0.0000 - 0.0000i -0.0000 + 0.0000i -0.0000 + 0.0000i 0.0000 + 0.0000i 0.0000 + 0.0000i -0.0000 - 0.0000i -0.0000 + 0.0000i 0.0000 + 0.0000i -0.0000 - 0.0000i 0.0000 + 0.0000i 0.0000 + 0.0000i -0.0000 - 0.0000i -0.0000 + 0.0000i 0.0000 + 0.0000i -0.0000 - 0.0000i 0.0000 - 0.0000i -0.0000 - 0.0000i 0.0000 + 0.0000i -0.0000 - 0.0000i -0.0000 + 0.0000i 0.0000 + 0.0000i -0.0000 - 0.0000i -0.0000 - 0.0000i 0.0000 + 0.0000i 0.0000 - 0.0000i 0.0000 - 0.0000i -0.0000 - 0.0000i -0.0000 + 0.0000i 0.0000 + 0.0000i -0.0000 - 0.0000i 0.0000 + 0.0000i -0.0000 - 0.0000i -0.0000 + 0.0000i 0.0000 + 0.0000i -0.0000 - 0.0000i -0.0000 + 0.0000i 0.0000 + 0.0000i 0.0000 + 0.0000i -0.0000 - 0.0000i 0.0000 + 0.0000i Columns 37 through 45 -0.0000 - 0.0000i 0.0000 + 0.0000i -0.0000 - 0.0000i 0.0000 + 0.0000i -0.0000 - 0.0000i 0.0000 + 0.0000i -0.0000 - 0.0000i 0.0000 + 0.0000i 0.0000 - 0.0000i 0.0000 + 0.0000i -0.0000 - 0.0000i -0.0000 - 0.0000i 0.0000 + 0.0000i -0.0000 - 0.0000i -0.0000 + 0.0000i 0.0000 + 0.0000i -0.0000 - 0.0000i -0.0000 + 0.0000i -0.0000 + 0.0000i 0.0000 + 0.0000i -0.0000 - 0.0000i -0.0000 - 0.0000i 0.0000 + 0.0000i -0.0000 - 0.0000i 0.0000 + 0.0000i -0.0000 - 0.0000i -0.0000 - 0.0000i -0.0000 - 0.0000i -0.0000 + 0.0000i 0.0000 + 0.0000i 0.0000 - 0.0000i -0.0000 - 0.0000i 0.0000 + 0.0000i -0.0000 - 0.0000i 0.0000 + 0.0000i 0.0000 - 0.0000i -0.0000 - 0.0000i 0.0000 + 0.0000i -0.0000 - 0.0000i 0.0000 + 0.0000i -0.0000 - 0.0000i 0.0000 + 0.0000i -0.0000 - 0.0000i -0.0000 + 0.0000i 0.0000 + 0.0000i Columns 46 through 54 0.0000 - 0.0000i -0.0003 - 0.0000i 0.0010 + 0.0004i -0.0020 - 0.0009i 0.0014 + 0.0012i 0.0019 + 0.0002i -0.0066 - 0.0033i 0.0150 + 0.0050i -0.0151 - 0.0113i 0.0000 + 0.0000i -0.0000 - 0.0000i -0.0001 + 0.0000i 0.0005 + 0.0001i -0.0011 - 0.0004i 0.0014 + 0.0006i -0.0038 - 0.0013i 0.0071 + 0.0035i -0.0020 - 0.0054i -0.0000 + 0.0000i 0.0003 + 0.0001i -0.0010 - 0.0004i 0.0019 + 0.0009i -0.0013 - 0.0013i -0.0030 - 0.0002i 0.0157 + 0.0054i -0.0375 - 0.0153i 0.0236 + 0.0265i 0.0000 + 0.0000i -0.0003 - 0.0001i 0.0011 + 0.0004i -0.0028 - 0.0011i 0.0038 + 0.0022i -0.0015 - 0.0020i -0.0099 - 0.0021i 0.0293 + 0.0114i -0.0229 - 0.0216i -0.0000 - 0.0000i -0.0002 - 0.0000i 0.0006 + 0.0003i -0.0008 - 0.0003i -0.0009 - 0.0000i 0.0061 + 0.0016i -0.0147 - 0.0069i 0.0308 + 0.0109i -0.0162 - 0.0197i Columns 55 through 63 -0.0008 + 0.0046i 0.0067 + 0.0029i -0.0224 + 0.0006i 0.1182 + 0.0336i -0.1062 - 0.0644i -0.0323 - 0.0002i -0.0565 + 0.0041i 0.1953 + 0.0846i -0.1126 - 0.0892i 0.0125 - 0.0022i -0.0271 - 0.0092i 0.0643 + 0.0210i -0.1383 - 0.0396i 0.1258 + 0.0937i -0.0502 - 0.0212i -0.0394 + 0.0168i -0.2951 - 0.0064i 0.3391 + 0.2131i 0.0482 + 0.0077i -0.1187 - 0.0589i 0.1865 + 0.0875i -0.2631 - 0.1498i 0.2799 + 0.1562i -0.2732 - 0.1642i 0.4976 + 0.1821i -0.5523 - 0.3620i 0.1267 + 0.2767i 0.0037 + 0.0041i 0.0179 + 0.0048i -0.0657 - 0.0223i 0.1022 + 0.0640i -0.1043 - 0.0490i 0.1332 + 0.0740i -0.3454 - 0.0927i 0.3656 + 0.2375i -0.1618 - 0.2051i -0.0074 + 0.0010i 0.0409 + 0.0105i -0.1255 - 0.0337i 0.0944 + 0.0862i -0.0470 + 0.0270i 0.0880 + 0.0654i -0.4120 - 0.1125i 0.2201 + 0.2145i 0.2103 - 0.0084i Columns 64 through 72 -0.0405 + 0.0231i 0.3476 + 0.0401i -0.3349 - 0.2459i -0.3398 + 0.1558i 0.6601 + 0.3561i -0.0726 - 0.3629i -0.3595 - 0.1502i 0.0657 + 0.2280i 0.0284 + 0.0957i 0.1252 - 0.1166i -0.2236 - 0.1675i 0.4673 + 0.0699i 0.4532 - 0.2724i -1.0651 - 0.5531i -0.1029 + 0.4122i 0.4644 + 0.3706i 0.0299 - 0.0097i -0.1805 - 0.0205i 0.4915 + 0.1927i -0.6645 - 0.4438i -0.3580 + 0.1766i 1.2267 + 0.6193i -0.6793 - 0.7074i -0.6112 + 0.0108i 0.7655 + 0.6298i 0.1169 - 0.2872i -0.1642 - 0.3419i -0.1874 - 0.0720i 0.4464 + 0.2328i 0.5017 - 0.1025i -0.7936 - 0.6243i -0.0408 + 0.2053i 0.3195 + 0.2593i -0.2727 - 0.0585i -0.1171 + 0.2229i 0.0926 + 0.2409i -0.2283 - 0.1976i 0.5995 + 0.0956i 0.5059 - 0.3290i -0.7641 - 0.6904i -0.4843 + 0.0398i 0.2976 + 0.5236i -0.0612 + 0.2954i -0.0585 + 0.2944i -0.0636 + 0.1589i Columns 73 through 81 -0.0440 + 0.0297i 0.0527 + 0.0367i 0.0031 - 0.0289i -0.0079 - 0.0151i 0.0030 + 0.0001i -0.0070 - 0.0008i -0.0034 + 0.0053i 0.0010 + 0.0052i 0.0004 + 0.0020i 0.0190 + 0.0733i -0.0439 - 0.0007i -0.0058 + 0.0304i 0.0012 + 0.0281i 0.0044 + 0.0195i 0.0042 + 0.0037i 0.0037 - 0.0036i 0.0004 - 0.0052i -0.0001 - 0.0031i 0.1138 - 0.0330i -0.0261 - 0.0725i -0.0611 - 0.0218i 0.0354 + 0.0415i -0.0162 - 0.0113i 0.0098 + 0.0054i 0.0077 - 0.0033i -0.0029 - 0.0081i -0.0000 - 0.0022i -0.0439 + 0.0143i 0.0221 - 0.0111i 0.0412 - 0.0309i -0.0131 - 0.0403i 0.0103 + 0.0001i -0.0047 - 0.0044i -0.0064 + 0.0004i 0.0018 + 0.0039i -0.0001 + 0.0003i -0.0075 + 0.0588i -0.0148 - 0.0074i 0.0188 + 0.0079i -0.0155 + 0.0047i 0.0094 + 0.0191i -0.0040 + 0.0034i 0.0008 + 0.0031i 0.0007 - 0.0000i 0.0002 - 0.0007i Columns 82 through 90 0.0003 + 0.0006i 0.0001 - 0.0000i -0.0000 - 0.0001i 0.0000 - 0.0000i -0.0000 - 0.0000i -0.0000 - 0.0000i -0.0000 - 0.0000i -0.0000 - 0.0000i 0.0000 + 0.0000i -0.0001 - 0.0012i -0.0001 - 0.0003i -0.0000 - 0.0000i -0.0000 + 0.0000i -0.0000 + 0.0000i 0.0000 + 0.0000i 0.0000 + 0.0000i 0.0000 + 0.0000i 0.0000 + 0.0000i -0.0007 - 0.0011i -0.0002 + 0.0000i 0.0000 + 0.0002i -0.0000 + 0.0001i 0.0000 + 0.0001i 0.0000 + 0.0000i 0.0000 + 0.0000i 0.0000 + 0.0000i 0.0000 - 0.0000i 0.0004 + 0.0003i 0.0001 - 0.0001i -0.0000 - 0.0002i 0.0000 - 0.0000i 0.0000 - 0.0000i -0.0000 - 0.0000i -0.0000 - 0.0000i -0.0000 - 0.0000i -0.0000 + 0.0000i 0.0001 - 0.0005i 0.0000 - 0.0003i -0.0000 - 0.0002i 0.0000 - 0.0000i -0.0000 - 0.0000i -0.0000 - 0.0000i -0.0000 - 0.0000i -0.0000 + 0.0000i 0.0000 + 0.0000i Columns 91 through 99 0.0000 + 0.0000i 0.0000 + 0.0000i 0.0000 + 0.0000i 0.0000 + 0.0000i 0.0000 + 0.0000i 0.0000 + 0.0000i 0.0000 + 0.0000i 0.0000 + 0.0000i 0.0000 + 0.0000i -0.0000 - 0.0000i -0.0000 - 0.0000i -0.0000 - 0.0000i -0.0000 - 0.0000i -0.0000 - 0.0000i -0.0000 - 0.0000i -0.0000 - 0.0000i -0.0000 - 0.0000i -0.0000 - 0.0000i -0.0000 - 0.0000i -0.0000 - 0.0000i -0.0000 - 0.0000i -0.0000 - 0.0000i -0.0000 - 0.0000i -0.0000 - 0.0000i -0.0000 - 0.0000i -0.0000 - 0.0000i -0.0000 - 0.0000i 0.0000 + 0.0000i 0.0000 + 0.0000i 0.0000 + 0.0000i 0.0000 + 0.0000i 0.0000 + 0.0000i 0.0000 + 0.0000i 0.0000 + 0.0000i 0.0000 + 0.0000i 0.0000 + 0.0000i 0.0000 + 0.0000i 0.0000 + 0.0000i 0.0000 + 0.0000i 0.0000 + 0.0000i 0.0000 + 0.0000i 0.0000 + 0.0000i 0.0000 + 0.0000i 0.0000 + 0.0000i 0.0000 + 0.0000i Columns 100 through 101 0.0000 + 0.0000i 0.0000 + 0.0000i -0.0000 - 0.0000i -0.0000 - 0.0000i -0.0000 - 0.0000i -0.0000 - 0.0000i 0.0000 + 0.0000i 0.0000 + 0.0000i 0.0000 + 0.0000i 0.0000 + 0.0000i
disp('Denominator coefficients:');
Denominator coefficients:
disp(denom);
1.0e+41 * Columns 1 through 9 0.0000 + 0.0000i -0.0000 - 0.0000i -0.0000 + 0.0000i -0.0000 + 0.0000i 0.0000 + 0.0000i 0.0000 + 0.0000i 0.0000 - 0.0000i -0.0000 - 0.0000i -0.0000 + 0.0000i Columns 10 through 18 0.0000 + 0.0000i -0.0000 - 0.0000i -0.0000 - 0.0000i 0.0000 - 0.0000i 0.0000 + 0.0000i -0.0000 - 0.0000i 0.0000 + 0.0000i 0.0000 - 0.0000i -0.0000 - 0.0000i Columns 19 through 27 -0.0000 + 0.0000i 0.0000 + 0.0000i -0.0000 - 0.0000i -0.0000 - 0.0000i 0.0000 + 0.0000i 0.0000 - 0.0000i -0.0000 - 0.0000i 0.0000 + 0.0000i -0.0000 - 0.0000i Columns 28 through 36 0.0000 + 0.0000i -0.0000 - 0.0000i 0.0000 - 0.0000i -0.0000 - 0.0000i 0.0000 + 0.0000i -0.0000 - 0.0000i 0.0000 + 0.0000i 0.0000 - 0.0000i -0.0000 - 0.0000i Columns 37 through 45 0.0000 + 0.0000i 0.0000 - 0.0000i -0.0000 - 0.0000i -0.0000 - 0.0000i 0.0000 + 0.0000i -0.0000 - 0.0000i 0.0000 + 0.0000i -0.0000 - 0.0000i -0.0000 + 0.0000i Columns 46 through 54 -0.0001 + 0.0000i 0.0008 + 0.0002i -0.0030 - 0.0010i 0.0063 + 0.0027i -0.0060 - 0.0042i -0.0013 + 0.0016i 0.0212 + 0.0067i -0.0470 - 0.0203i 0.0048 + 0.0256i Columns 55 through 63 0.0640 + 0.0258i -0.1151 - 0.0483i 0.3069 + 0.1080i -0.4397 - 0.2582i 0.2524 + 0.1529i -0.2361 - 0.1209i 0.8526 + 0.2673i -0.7918 - 0.5489i 0.1405 + 0.2889i Columns 64 through 72 0.7023 + 0.2472i -1.4789 - 0.6347i -1.0668 + 0.5173i 2.4499 + 1.6315i -0.1430 - 0.8019i -1.1907 - 0.7962i 0.9387 + 0.3210i 0.2583 - 0.5671i -0.2094 - 0.5684i Columns 73 through 81 0.1264 - 0.0422i -0.0276 + 0.0025i -0.1141 + 0.0197i 0.0472 + 0.0732i -0.0264 - 0.0153i 0.0129 + 0.0031i 0.0142 - 0.0041i -0.0040 - 0.0103i 0.0001 - 0.0021i Columns 82 through 90 -0.0010 - 0.0010i -0.0003 + 0.0002i 0.0001 + 0.0004i -0.0001 + 0.0001i 0.0000 + 0.0001i 0.0000 + 0.0000i 0.0000 + 0.0000i 0.0000 + 0.0000i 0.0000 - 0.0000i Columns 91 through 99 -0.0000 - 0.0000i -0.0000 - 0.0000i -0.0000 - 0.0000i -0.0000 - 0.0000i -0.0000 - 0.0000i -0.0000 - 0.0000i -0.0000 - 0.0000i -0.0000 - 0.0000i -0.0000 - 0.0000i Columns 100 through 101 -0.0000 - 0.0000i -0.0000 - 0.0000i
This approach avoids memory issues while ensuring the system dynamics are preserved.
Some helpful reference links for the same:

Kategorien

Mehr zu Mathematics finden Sie in Help Center und File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by