2.60 repeat each column of matrix number of times

Gives a matrix, repeate each column a number of time, say 3 times, in place to produce a matrix 3 times as wide as the original.

kron() in Matlab and KroneckerProduct in Mathematica and Maple can be used for this.

Mathematica

mat = {{1, 2, 3, 4}, 
       {5 , 6, 7, 8}, 
       {9, 10, 11, 12}} 
 
KroneckerProduct[mat, {1, 1, 1}]
 

Another method that can be used in this, but the above is better

r = Map[#*{1, 1, 1} &, mat, {2}] 
Partition[Flatten[r], 12]
 

{{1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4}, 
 {5, 5, 5, 6, 6, 6, 7, 7, 7, 8, 8, 8}, 
 {9, 9, 9, 10, 10, 10, 11, 11, 11, 12, 12, 12}}
 

 

Matlab

A=[1 2 3 4; 
   5 6 7 8; 
   9 10 11 12]; 
kernel=ones(1,3); 
kron(A,kernel)
 

ans = 
1  1  1  2  2   2  3   3  3  4  4   4 
5  5  5  6  6   6  7   7  7  8  8   8 
9  9  9  10 10  10 11  11 11 12 12  12
 

 

Maple

restart; 
mat := Matrix([[1, 2, 3,4], [5, 6,7,8], [9,10,11,12]]); 
kernel :=  Vector[row]([1,1,1]); 
LinearAlgebra:-KroneckerProduct(mat,kernel);
 

\[ \left [\begin {array}{cccccccccccc} 1 & 1 & 1 & 2 & 2 & 2 & 3 & 3 & 3 & 4 & 4 & 4 \\ 5 & 5 & 5 & 6 & 6 & 6 & 7 & 7 & 7 & 8 & 8 & 8 \\ 9 & 9 & 9 & 10 & 10 & 10 & 11 & 11 & 11 & 12 & 12 & 12 \end {array}\right ] \]