Info

This question is locked. 編集または回答するには再度開いてください。

Tridiagonal Matrix with subdiagonal and main diagonal is also matrix

5 ビュー (過去 30 日間)
Mücahit Özalp
Mücahit Özalp 2021 年 5 月 12 日
Locked: Steven Lord 2024 年 7 月 13 日
I have two matrices A and B. I want A to be main diagonal and B to be my subdiagonals. How do I create such a matrix? By the way sizes of A and B changes but they are square matrices.
Specifically, a1=4,b1=-1
A =diag(a1*ones(1,N-1)) + diag(b1*ones(1,N-2),1) + diag(b1*ones(1,N-2),-1)
B=(-1)*eye(N-1)
These are my A and B matrices. I need to define a (N-1)*(N-1) times (N-1)*(N-1) matrix . For example for N=1000 or N=5000 I should be able to change the N value.
  14 件のコメント
Mücahit Özalp
Mücahit Özalp 2021 年 5 月 14 日
編集済み: Mücahit Özalp 2021 年 5 月 14 日
@Matt JIt's me again now I can form the matrix for N=5000 but I need to evaluate its smallest 10 eigenvalues using E=eigs(D,10,'smallestabs'); I get out of memory error. Is there a way to solve that.
Matt J
Matt J 2021 年 5 月 14 日
I don't think so, but if you post a new question on it (ideally with a demo), others on the forum may have some thoughts.

採用された回答

Matt J
Matt J 2021 年 5 月 12 日
編集済み: Matt J 2021 年 5 月 12 日
So, you want a block Toeplitz matrix?
N = 5;
A =diag([7 4 4]);
B=[8 8 10; 2 5 2; 10 8 7];
C=zeros(3);
blocks={C,B,A};
result=cell2mat(blocks( toeplitz(1+[2,1,zeros(1,N-2)]) ))
result = 15×15
7 0 0 8 8 10 0 0 0 0 0 0 0 0 0 0 4 0 2 5 2 0 0 0 0 0 0 0 0 0 0 0 4 10 8 7 0 0 0 0 0 0 0 0 0 8 8 10 7 0 0 8 8 10 0 0 0 0 0 0 2 5 2 0 4 0 2 5 2 0 0 0 0 0 0 10 8 7 0 0 4 10 8 7 0 0 0 0 0 0 0 0 0 8 8 10 7 0 0 8 8 10 0 0 0 0 0 0 2 5 2 0 4 0 2 5 2 0 0 0 0 0 0 10 8 7 0 0 4 10 8 7 0 0 0 0 0 0 0 0 0 8 8 10 7 0 0 8 8 10
  8 件のコメント
Matt J
Matt J 2021 年 5 月 12 日
N = 1000;
a1=4;b1=-1;
A =diag(a1*ones(1,N-1)) + diag(b1*ones(1,N-2),1) + diag(b1*ones(1,N-2),-1);
B=(-1)*speye(N-1) ;
C=sparse(N-1,N-1);
blocks={C,B,sparse(A)};
result=cell2mat(blocks( toeplitz(1+[2,1,zeros(1,N-3)]) ));
whos result
Name Size Bytes Class Attributes result 998001x998001 103680256 double sparse
Mücahit Özalp
Mücahit Özalp 2021 年 5 月 12 日
@Matt J This works now. Awesome.

その他の回答 (1 件)

Matt J
Matt J 2021 年 5 月 12 日
Here's another way, probably much faster.
N=1000;
a1=4;b1=-1;
A =diag(a1*ones(1,N-1)) + diag(b1*ones(1,N-2),1) + diag(b1*ones(1,N-2),-1);
B=(-1)*eye(N-1);
E0=speye(N);
E1=E0(2:end,1:end-1);
E0=E0(1:end-1,1:end-1);
result=kron(E0,A) + kron(E1,B)+kron(E1.',B);
whos result
Name Size Bytes Class Attributes result 998001x998001 87760160 double sparse
  1 件のコメント
Mücahit Özalp
Mücahit Özalp 2021 年 5 月 12 日
Yeah much much faster.

This question is locked.

カテゴリ

Help Center および File ExchangeOperating on Diagonal Matrices についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by