Kron

Renvoie le produit de Kronecker de deux matrices, matrice et vecteur, vecteur et matrice ou deux vecteurs.

matrix matrix::Kron(
  const matrix&  b      // deuxième matrice
   );
 
matrix matrix::Kron(
  const vector&  b      // vecteur
   );
 
matrix vector::Kron(
  const matrix&  b      // matrice
   );
 
matrix vector::Kron(
  const vector&  b      // deuxième vecteur
   );
 

Paramètres

b

[in]  Deuxième matrice.

Valeur de Retour

Matrice.

Note

Le produit de Kronecker est également appelé multiplication matricielle par blocs.

 

Un algorithme simple pour le produit de Kronecker pour deux matrices en MQL5 :

matrix MatrixKronecker(const matrixmatrix_a,const matrixmatrix_b)
  {
   ulong  M=matrix_a.Rows();
   ulong  N=matrix_a.Cols();
   ulong  P=matrix_b.Rows();
   ulong  Q=matrix_b.Cols();
   matrix matrix_c(M*P,N*Q);
 
   for(ulong m=0m<Mm++)
      for(ulong n=0n<Nn++)
         for(ulong p=0p<Pp++)
            for(ulong q=0q<Qq++)
               matrix_c[m*P+p][n*Q+q]=matrix_a[m][n] * matrix_b[p][q];
 
   return(matrix_c);
  }

 

Exemple en MQL5 :

   matrix a={{1,2,3},{4,5,6}};
   matrix b=matrix::Identity(2,2);
   vector v={1,2};
 
   Print(a.Kron(b));
   Print(a.Kron(v));
 
  /*
   [[1,0,2,0,3,0]
    [0,1,0,2,0,3]
    [4,0,5,0,6,0]
    [0,4,0,5,0,6]]
 
   [[1,2,2,4,3,6]
    [4,8,5,10,6,12]]
  */

 

Exemple en Python :

import numpy as np
 
A = np.arange(1,7).reshape(2,3)
B = np.identity(2)
V = [1,2]
print(np.kron(AB))
print("")
print(np.kron(AV))
 
[[102030.]
 [010203.]
 [405060.]
 [040506.]]
 
[[ 1  2  2  4  3  6]
 [ 4  8  5 10  6 12]]