# Matrix times array

버전 1.0.0 (3.2 KB) 작성자:
Fast multiplication of multi-dimensional array x by matrix A along dim. n (or: mode-n product of tensor x and matrix A)
다운로드 수: 13
업데이트 날짜: 2021/12/20

라이선스 보기

out = MatrixTimesArray(A,x,i);
Multiplication of multi-dimensional array x by matrix A along dimension i. This is equivalent to mode-i product of tensor x by matrix A in tensor language, see for example De Lathauwer et al. (SIAM 2000). No further mex-files needed.
Elements of output are determined by the formula:
The function reshapes x into a matrix (performing a permute, if necessary) and then either pre- or post-multiplies it by A, whichever minimizes permute operations). If x is a matrix, the following equivalence holds to conventional matrix algebra:
A*x = MatrixTimesArray(A,x,1); % dim. 1: matrix pre-multiplication
x*B'= MatrixTimesArray(B,x,2); % dim. 2: matrix post-multiplication
As for speed: For large arrays, note that the permute operations cost time time, not the reshape. Thus, put most computationally intense dimensions on first (preferred) and last dimension.
Inputs:
A: matrix, full or sparse.
x: k-dimensional array of size
i: Scalar, optional. Along which dimension to multiply. If omitted, the function multiplies along the first compatible dimension
Output:
: k-dimensional array of size . Note that the size of dimension i has changed from to m with respect to the input x.
Example:
A = rand(60,30); % Matrix A: 60-by-30.
x = rand(50,30,20); % Array/tensor x: (50,30,20)
y = MatrixTimesArray(A,x,2); % Multiply along dimension 2:
size(y) % y is (50,60,20) array.
yy= MatrixTimesArray(A,x); % Omitting last input (dim.) gives same result.
norm(yy(:)-y(:));
Version: 20-Dec-2021
Acknowledgement: This code follows the same idea as my function 'kronm.m', which carries out a series of MatrixTimesArray / n-mode products on a tensor.

### 인용 양식

Matthias Kredler (2024). Matrix times array (https://www.mathworks.com/matlabcentral/fileexchange/103825-matrix-times-array), MATLAB Central File Exchange. 검색됨 .

개발 환경: R2021b
모든 릴리스와 호환
##### 플랫폼 호환성
Windows macOS Linux

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
버전 게시됨 릴리스 정보
1.0.0