What is the best vectorized way to construct the following matrix
Afficher commentaires plus anciens
I have a system of linear equations:
y = A x
y is a column vector of size n. A is a lower triangular matrix of size n by n. x is a column vector of size n.
I want to construct the following block diagonal matrix
the first block is [y(1) A(1,1); x(1) 1;]
which is just 2 by 2 matrix
the second block is [y(2) A(2,1) A(2,2); x(1) 1 0; x(2) 0 1;];
which is 3 by 3 matrix
the kth block should look like [y(k) A(k,1) ... A(k,k); x(1:k) eye(k);];
which is a k+1 by k+1 matrix.
If it will help, we can assume that A is a lower triangular toeplitz matrix This means that the diagonal of A is constant = A(1,1) The 1st sub-diagonal is constant and = A(2,1)
Réponse acceptée
Plus de réponses (1)
rantunes
le 8 Mar 2015
Hey,
In a glance, it seems that the best way to implement is to do it block by block.
B = zeros(k+1,k+1);
for i = 1:k+1
if i == 1
B(i,1) = y(k);
end
B(i,1) = x(i-1);
end
for i = 1:k
B(1,i+1) = A(k,i);
end
for i = 2:k+1
for j = 2:k+1
if i == j
B(i,j) = 1;
end
end
end
Catégories
En savoir plus sur Creating and Concatenating Matrices dans Centre d'aide et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!