I want to build the matrix
Ältere Kommentare anzeigen
I want to build the matrix G from a square matrix A, which has n×n dimensions.
The matrix G is defined as :
G = [ I O O O ...;
A I O O ... ;
A^2 A I O ...;
A^3 A^2 A I ...]
where:
- I is the n×n identity matrix (I=eye(n)),
- O is the n×n zero matrix (O=zeros(n)).
The resulting G has dimensions (n⋅m)×(n⋅m), where m is the number of block rows and columns in G
Can any one Help me
Thanx
3 Kommentare
Mr. Pavl M.
am 31 Dez. 2024
Bearbeitet: Mr. Pavl M.
am 31 Dez. 2024
Do you need the G to contain more powers of A, like A^4, A^5 till m or just powers of A till A^3?
Do you need it in loop or loop-free solution?
Something like (approximately): G = [eye(n) zeros((m-1)*n,(m-1)*n);A eye(n) zeros((m-2)*n,(m-2)*n); A*A A eye(n) zeros((m-3)*n,(m-3)*n);A*A*A A*A A eye(n) zeros((m-4)*n,(m-4)*n) ?
- Good question and good answer of Stephen23 and M. Agarwal, I checked both are correct, first is with no explicit loops, second is with 1 loop, I tested the running times and in 2 IDEs (both in Mt-b and Oc-e it runs, who will require it in TCE Julia, in TCE Python?), the 2 constructing methods summarized: as well,why function runs faster?:
clc
clear all
close all
m = 4;
n = 3;
A = randi(9,n)
C = [{zeros(n),eye(n)},arrayfun(@(p)A^p,1:m-1,'uni',0)];
tic
t1 = cputime;
G1 = cell2mat(C(1+tril(toeplitz(1:m))))
toc
t2 = cputime;
display(t2-t1)
function G = constructG(A, m)
n = size(A, 1);
% Create block diagonal of identity matrices
G = kron(eye(m), eye(n));
% Fill lower triangular blocks with powers of A
current_power = A;
for i = 1:m-1
% Fill the i-th subdiagonal
for j = 1:m-i
row_idx = (i+j-1)*n + (1:n);
col_idx = (j-1)*n + (1:n);
G(row_idx, col_idx) = current_power;
end
if i < m - 1
current_power = current_power * A;
end
end
end
tic
t1 = cputime;
G2 = constructG(A, m)
toc
t2 = cputime;
display(t2-t1)
Husam
am 31 Dez. 2024
Akzeptierte Antwort
Weitere Antworten (1)
m = 4;
n = 3;
A = randi(9,n)
C = [{zeros(n),eye(n)},arrayfun(@(p)A^p,1:m-1,'uni',0)];
G = cell2mat(C(1+tril(toeplitz(1:m))))
1 Kommentar
Husam
am 31 Dez. 2024
Kategorien
Mehr zu Mathematics finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
