在Matlab中向量化成对Kronecker乘积 [英] Vectorize the pairwise kronecker product in matlab

查看:451
本文介绍了在Matlab中向量化成对Kronecker乘积的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设有两个相同大小的矩阵,我想计算它们的列式克罗内克积的总和.由于有时列的尺寸很大,因此速度可能很慢.因此,是否有矢量化该功能的方法,或者任何功能都可以帮助降低matlab的复杂性?提前致谢.

Suppose there are two matrices of the same size, and I want to calculate the summation of their column-wise kronecker product. Due to sometimes the column size is quite large so that the speed could be very slow. Thus, is there anyway to vectorize this function or any function may help reducing the complexity in matlab? Thanks in advance.

下面提供了带有for循环的相应matlab代码,而d的答案是感兴趣的输出:

The corresponding matlab code with a for-loop is provided below, and the answer of d is the interested output:

A = rand(3,7);
B = rand(3,7);
d = zeros(size(A,1)*size(B,1),1);
for i=1:size(A,2)
    d = d + kron(A(:,i),B(:,i));
end

推荐答案

使用Daniels答案给出的Kronecker产品的重写

Using the rewriting of the Kronecker product given by Daniels answer

e=zeros(size(B,1),size(A,1));
for i=1:size(A,2)
    e = e + B(:,i)*A(:,i).';
end
e=reshape(e,[],1);

我们这么说

C = A'

因此

for i=1:m
    e = e + B(:,i)*C(i,:);
end

这是矩阵乘积的定义

B*C.

总而言之,可以通过简单的矩阵乘积来解决问题

In conclusion the problem can thus be solved by the simple matrix product

d = reshape(B*A',[],1);

这篇关于在Matlab中向量化成对Kronecker乘积的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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