MATLAB:使用相同的重复块创建块对角矩阵 [英] MATLAB: Create a block diagonal matrix with same repeating block

查看:193
本文介绍了MATLAB:使用相同的重复块创建块对角矩阵的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个尺寸为 n x n 的矩阵 K .我想创建一个尺寸为 N x N 的新块对角矩阵 M ,以使其包含矩阵 K 作为对角线.

I have a matrix K of dimensions n x n. I want to create a new block diagonal matrix M of dimensions N x N, such that it contains d blocks of matrix K as its diagonal.

如果 d 较小,我会直接使用 M = blkdiag(K,K,K)等.不幸的是, d 很大,我不想为 blkdiag()函数使用与 d 完全相同的参数手动编写公式.

I would have directly used M = blkdiag(K,K,K) etc. had d been smaller. Unfortunately, d is very large and I don't want to manually write the formula with d exactly same arguments for the blkdiag() function.

有没有更短,更聪明的方法?

Is there any shorter, smarter way to do this?

推荐答案

,您可以使用kron.

M = kron(X,Y)

返回X和Y的Kronecker张量积.结果是通过取X和Y的元素之间所有可能的乘积形成的大数组.如果X是m-by-n,Y是p-by- q,则kron(X,Y)为m * p-n * q.因此,在您的情况下,将执行以下操作:

returns the Kronecker tensor product of X and Y. The result is a large array formed by taking all possible products between the elements of X and those of Y. If X is m-by-n and Y is p-by-q, then kron(X,Y) is m*p-by-n*q. So in your case something like this will do:

M = kron(eye(L),K)

带有L个块.

这篇关于MATLAB:使用相同的重复块创建块对角矩阵的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆