Tridiagonal Matrix with subdiagonal and main diagonal is also matrix
情報
This question is locked. 編集または回答するには再度開いてください。
古いコメントを表示
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 件のコメント
Stephan
2021 年 5 月 12 日
Please give a small example of what you want as result
Mücahit Özalp
2021 年 5 月 12 日
編集済み: Mücahit Özalp
2021 年 5 月 12 日
Walter Roberson
2021 年 5 月 12 日
I do not know what it means for a square matrix to be a subdiagonal?
Mücahit Özalp
2021 年 5 月 12 日
I am also confused by your terminology. Let's take a look at a very small example:
N = 5;
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)
It seems that you are saying that A and B, as defined above, are the inputs to the new matrix you want. Can you tell us what the output should be? Don't just describe it. Please write the output, ideally in MATLAB syntax.
Mücahit Özalp
2021 年 5 月 12 日
the cyclist
2021 年 5 月 12 日
I was not asking you to make the general algorithm. I was asking you what the output would be for that one small example.
But I think what you just posted makes it clearer.
Mücahit Özalp
2021 年 5 月 12 日
編集済み: Mücahit Özalp
2021 年 5 月 12 日
Jan
2021 年 5 月 12 日
You mention the general form "[(N-1)^2] x [(N-1)^2]" and post a 12x12 matrix as example, which does not match this format.
You mention: "B=(-1)*eye(N-1)" but the example contains multiple different full 3x3 matrices.
Please post small examples e.g. for N==3 including all inputs and a manually constructed output. Maybe an N=4 example is required.
Mücahit Özalp
2021 年 5 月 12 日
Mücahit Özalp
2021 年 5 月 12 日
Mücahit Özalp
2021 年 5 月 12 日
Mücahit Özalp
2021 年 5 月 14 日
編集済み: Mücahit Özalp
2021 年 5 月 14 日
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.
採用された回答
その他の回答 (1 件)
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 件のコメント
Mücahit Özalp
2021 年 5 月 12 日
This question is locked.
カテゴリ
ヘルプ センター および File Exchange で Operating on Diagonal Matrices についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


