本文介绍了在Matlab中使用重复块创建块对角线和对角线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有一个n by- n矩阵A和一个n by- n矩阵B.我想创建一个由矩阵AN个块作为对角线以及矩阵B的(N -1)个块作为A对角线以下的对角线组成的块矩阵C.

Suppose I have an n-by-n matrix A and an n-by-n matrix B. I want to create a block matrix C consisting of N blocks of matrix A as a diagonal and (N-1) blocks of matrix B as a subdiagonal below the A diagonal.

链接为以下问题提供了答案只有街区对角线的情况,都很棒.现在我想添加一个块对角线,我应该在Matlab中使用哪个命令?

This link gives answers for only the block diagonal case, which are all great. Now I want to add a block subdiagonal, which command in Matlab should I use?

非常感谢您的帮助.

推荐答案

如果您知道如何创建对角线A(大小为nN -by- nN)的矩阵C,则可以也可以创建较小尺寸的矩阵D(n(N-1)-n(N-1)),其对角线为B,则只需在C的右子矩阵处添加D:

If you know how to create a matrix C with A on its diagonal (of size nN-by-nN), you can also create a matrix D of smaller size (n(N-1)-by-n(N-1)) with B on its diagonal, then you just need to add D at the right sub-matrix of C:

C( (n+1):end, (n+1):end ) = C( (n+1):end, (n+1):end ) + D;

或者,使用 kron :

Alternatively, using kron:

C = kron( eye(n), A ) + kron( diag(ones(n-1,1), -1), B );

在这里使用稀疏矩阵可能会更好

You might be better off using sparse matrices here

C = kron( speye(n), A ) + kron( spdiag(ones(n-1,1), -1, n, n), B );

这篇关于在Matlab中使用重复块创建块对角线和对角线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-15 19:51