Info
This question is locked. Öffnen Sie sie erneut, um sie zu bearbeiten oder zu beantworten.
Tridiagonal Matrix with subdiagonal and main diagonal is also matrix
5 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Mücahit Özalp
am 12 Mai 2021
Locked: Steven Lord
am 13 Jul. 2024
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 Kommentare
Matt J
am 14 Mai 2021
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.
Akzeptierte Antwort
Matt J
am 12 Mai 2021
Bearbeitet: Matt J
am 12 Mai 2021
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)]) ))
8 Kommentare
Matt J
am 12 Mai 2021
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
Weitere Antworten (1)
Matt J
am 12 Mai 2021
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
1 Kommentar
This question is locked.
Siehe auch
Kategorien
Mehr zu Operating on Diagonal Matrices 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!