フィルターのクリア

How to combine two matrices

2 ビュー (過去 30 日間)
Emilia
Emilia 2020 年 12 月 10 日
コメント済み: Walter Roberson 2020 年 12 月 10 日
Hello,
I want matrix d to go into matrix A.
Thanks in advance
n=4
A = 4*diag(ones(n^2,1)) - diag(ones(n^2-1,1),-1) - diag(ones(n^2-1,1),1)
d1=diag(-1*ones(n^2,1),-3);
d2=diag(-1*ones(n^2,1),3);
d=d1+d2

回答 (1 件)

Walter Roberson
Walter Roberson 2020 年 12 月 10 日
Where in A should d go?
Note that A is going to be an n^2 by n^2 array as you put something of length n^2 along the main diagonal, and the other two diagonals have had their length adjusted properly to be consistent.
Note that d is going to be an (n^2+3) by (n^2+3) array, as the length of the third diagonal is n^2, so the length of the second diagonal would be n^2 + 1 so the length of the first diagonal would be n^2 + 2 so the length of the main diagonal would be n^2 + 3.
So you cannot put d within A. You could put A within d.
What I suspect you want is to fix your sizes for d1 and d2, and then use
A = A + d
  2 件のコメント
Emilia
Emilia 2020 年 12 月 10 日
I want the matrix to look like this.
Walter Roberson
Walter Roberson 2020 年 12 月 10 日
You just have to correct the lengths for d1 and d2, and
A = A + d

サインインしてコメントする。

カテゴリ

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