フィルターのクリア

How to assign a matrix instead of scalar in another matrix at specified locations with or without kronecker product?

1 回表示 (過去 30 日間)
Hello all,
I have a tri-diagonal matrix F (n-by-n) and a diagonal matrix G(n-by-n). Now, I want to construct a matrix A(n^2-by-n^2) (with kronecker product or without it) with matrix F lying on main diagonal of A (A becomes a tri-diagonal matrix after this step) and putting G on the 2 adjacent diagonals (A becomes a penta-diagonal matrix after this step).
Any thoughts about how this could be done?
Thank you.

採用された回答

Guillaume
Guillaume 2017 年 7 月 6 日
編集済み: Guillaume 2017 年 7 月 6 日
There may be something in gallery, otherwise this would work:
elems = {F, G, zeros(size(F))};
result = cell2mat(elems(min(toeplitz(1:size(F, 1)), 3)))
  2 件のコメント
Udit Srivastava
Udit Srivastava 2017 年 7 月 6 日
works good but I have a small doubt. How is that '3' (in 2nd line) helping?
Guillaume
Guillaume 2017 年 7 月 6 日
The whole idea is to generate an indexing matrix that chooses between F, G, and the zeros. Therefore you only want indices between 1 and 3. My min(toeplitz(1:size(F, 1)), 3) is just one way of generating that indexing matrix. Other possibilities:
toeplitz(min(1:size(F, 1), 3))
toeplitz([1:3, repmat(3, size(F, 1)-2, 1))
gallery('tridiag', size(F, 1), 1, 2, 1) + 1 %with this one you have to change the order in elems to {0, G, F}

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

その他の回答 (0 件)

カテゴリ

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