hello, I want to make this array of matrices where R and Id are NxN matrices. The array must be N2 x N2. Any help?

Answers (2)

Image Analyst
Image Analyst on 9 Dec 2021

0 votes

I'm sure there are fancier, more compact but cryptic ways using kron(), hankel(), toeplitz(), blkdiag() or some such functions, but did you just try a simple for loop?

1 Comment

Hello, finally use the command A=cell(NxN) which allows you to enter matrices per cell. Then to convert the set of cells to a single matrix use the command A1=cell2mat(A).

Sign in to comment.

Matt J
Matt J on 9 Dec 2021
Edited: Matt J on 9 Dec 2021
N=4;
R=toeplitz([4 -1 zeros(1,N-2)]);
Id=speye(N);
k=toeplitz([1,2, repmat(3,1,N-2) ]);
blocks={R,-Id,0*Id};
A1=cell2mat(blocks(k));
full(A1)
ans = 16×16
4 -1 0 0 -1 0 0 0 0 0 0 0 0 0 0 0 -1 4 -1 0 0 -1 0 0 0 0 0 0 0 0 0 0 0 -1 4 -1 0 0 -1 0 0 0 0 0 0 0 0 0 0 0 -1 4 0 0 0 -1 0 0 0 0 0 0 0 0 -1 0 0 0 4 -1 0 0 -1 0 0 0 0 0 0 0 0 -1 0 0 -1 4 -1 0 0 -1 0 0 0 0 0 0 0 0 -1 0 0 -1 4 -1 0 0 -1 0 0 0 0 0 0 0 0 -1 0 0 -1 4 0 0 0 -1 0 0 0 0 0 0 0 0 -1 0 0 0 4 -1 0 0 -1 0 0 0 0 0 0 0 0 -1 0 0 -1 4 -1 0 0 -1 0 0

Categories

Find more on MATLAB in Help Center and File Exchange

Edited:

on 9 Dec 2021

Community Treasure Hunt

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

Start Hunting!