How read Matrix Market data into MATLAB?

Hello. I'd like to read matrix data from the following link: https://morwiki.mpi-magdeburg.mpg.de/morwiki/index.php/Linear_1D_Beam
The link tells me that it is in Matrix Market format, but I am unsure how to extract the M, E, K, B, and C matrices from the attached .m file. Could someone help me extract the data? I'd like to have access to the M, E, K, B, and C matrices the correspond to the following equation:
Here is what the .m file, LF10.m, looks like. There are 18 rows. There is also a .b, .c, .e, and .k file:
  • Thank you

답변 (2개)

jonas-schulze
jonas-schulze 2022년 7월 12일
편집: jonas-schulze 2022년 7월 12일

1 개 추천

If you would like to obtain a sparse matrix, you can try load and spconvert
load LF10.m
M = spconvert(LF10(2:end,:))
or sparse if the matrix has some leading or trailing zero columns or rows
load LF10.m
m = LF10(1, 1)
n = LF10(1, 2)
i = LF10(2:end, 1)
j = LF10(2:end, 2)
v = LF10(2:end, 3)
M = sparse(i, j, v, m, n)
If the underlying matrix is symmetric, the market file will only contain half the matrix. In this case it's the lower triangular part, but I don't know whether it always is.
D = diag(diag(M))
L = tril(M, -1)
M = L + D + L'
Alan Stevens
Alan Stevens 2021년 7월 15일

0 개 추천

Do you mean like this:
%%MatrixMarket matrix coordinate real symmetric
% System: M x_dotdot + E x_dot + K x = B u
% y = C x
%
% Steel beam, 5 nodes
% Properties: Length: 0.1 m, Density: 8000 kg/m^3, Diameter: 1 mm,
% Modulus of elasticity: 2.0e11 Pa, Poisson ratio: 0.29,
% Contr.of M to damping: 1e2, Contr. of K to damping: 1e-2.
% The output node is the node in the middle.
%
Mx = [18 18 50
1 1 8.2666855418381347E-11
2 1 2.3970604543209878E-08
2 2 5.1946160853333332E-05
3 1 -6.1709237860082308E-11
3 3 1.6533371083676269E-10
4 2 8.9335862399999995E-06
4 3 2.3970604543209878E-08
4 4 5.1946160853333332E-05
5 2 -2.3970604543209878E-08
5 3 -6.1709237860082308E-11
5 5 1.6533371083676269E-10
6 4 8.9335862399999995E-06
6 5 2.3970604543209878E-08
6 6 5.1946160853333332E-05
7 4 -2.3970604543209878E-08
7 5 -6.1709237860082308E-11
7 7 1.6533371083676269E-10
8 6 8.9335862399999995E-06
8 7 2.3970604543209878E-08
8 8 5.1946160853333332E-05
9 6 -2.3970604543209878E-08
9 7 -6.1709237860082308E-11
9 9 1.6533371083676269E-10
10 8 8.9335862399999995E-06
10 9 2.3970604543209878E-08
10 10 5.1946160853333332E-05
11 8 -2.3970604543209878E-08
11 9 -6.1709237860082308E-11
11 11 1.6533371083676269E-10
12 10 8.9335862399999995E-06
12 11 2.3970604543209878E-08
12 12 5.1946160853333332E-05
13 10 -2.3970604543209878E-08
13 11 -6.1709237860082308E-11
13 13 1.6533371083676269E-10
14 12 8.9335862399999995E-06
14 13 2.3970604543209878E-08
14 14 5.1946160853333332E-05
15 12 -2.3970604543209878E-08
15 13 -6.1709237860082308E-11
15 15 1.6533371083676269E-10
16 14 8.9335862399999995E-06
16 15 2.3970604543209878E-08
16 16 5.1946160853333332E-05
17 14 -2.3970604543209878E-08
17 15 -6.1709237860082308E-11
17 17 1.6533371083676269E-10
18 16 -2.3970604543209878E-08
18 17 -6.1709237860082308E-11
18 18 8.2666855418381347E-11];
M = zeros(18,18);
for r = 2:51
M(Mx(r,1), Mx(r,2)) = Mx(r,3);
end
disp(M)
1.0e-04 * 0.0000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.0002 0.5195 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -0.0000 0 0.0000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.0893 0.0002 0.5195 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -0.0002 -0.0000 0 0.0000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.0893 0.0002 0.5195 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -0.0002 -0.0000 0 0.0000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.0893 0.0002 0.5195 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -0.0002 -0.0000 0 0.0000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.0893 0.0002 0.5195 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -0.0002 -0.0000 0 0.0000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.0893 0.0002 0.5195 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -0.0002 -0.0000 0 0.0000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.0893 0.0002 0.5195 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -0.0002 -0.0000 0 0.0000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.0893 0.0002 0.5195 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -0.0002 -0.0000 0 0.0000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -0.0002 -0.0000 0.0000

댓글 수: 5

To be honest, I'm not sure. I was hoping to have 5 matrices, but that seems to only be 1 matrix.
Alan Stevens
Alan Stevens 2021년 7월 15일
I assume the data for the other matrices is in the other files. I only looked at LF10.m. There are other files in the zip file.
Now that I look more into it, I suspect that the matrix should actually be the following 18x18 matrix:
I believe this since it dawned on me that the LF10.m file is structured as rowIndex, colIndex, value in each row to construct a sparse matrix. I found the full matrix above through mmread.m from https://math.nist.gov/MatrixMarket/mmio/matlab/mmiomatlab.html
However, thank you for your help.
Also, you were right about the other matrices being in the other files.
I was confused at why there is only one matrix, but then I figured it out: the .m file is the M matrix, the .k file is the K matrix, and so on. Assuming that this is true, then this is a prime example of why you should never put a . in your filenames.
Alan Stevens
Alan Stevens 2021년 7월 16일
Yes, that's the same matrix I regenerated from your file (the numbers are just displayed slightly differently).

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Logical에 대해 자세히 알아보기

제품

릴리스

R2020a

질문:

2021년 7월 15일

편집:

2022년 7월 12일

Community Treasure Hunt

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

Start Hunting!

Translated by