Linear Algebra and the C Language/a0hl


In linear algebra, a circulant matrix is a square matrix in which all rows are composed of the same elements and each row is rotated one element to the right relative to the preceding row. It is a particular kind of Toeplitz matrix.... Wikipedia: Circulant matrix


Install and compile this file in your working directory.

/* ------------------------------------ */
/*  Save as :   c00g.c                  */
/* ------------------------------------ */
#include "v_a.h"
/* ------------------------------------ */
#define   RC  RC6
/* ------------------------------------ */
int main(void)
{
/* Toeplitz Matrix 
   
        V
 
   U    1 5 6 7
        2 
        3         
        4
     
  */
  
double u1[R1*RC]={ 1,2,3,4,5,6};
double v1[RC*C1]={ 1,
	               6,
	               5,
	               4,
	               3,
	               2};

double u2[R1*RC]={ 7,5,6,8,9,4};
double v2[RC*C1]={ 7,
	               4,
	               9,
	               8,
	               6,
	               5};
	              	                 
double **V1   = ca_A_mR(v1,i_mR(RC,C1));	
double **U1   = ca_A_mR(u1,i_mR(R1,RC));
double **A   =            i_mR(RC,RC);

double **V2   = ca_A_mR(v2,i_mR(RC,C1));	
double **U2   = ca_A_mR(u2,i_mR(R1,RC));
double **B   =             i_mR(RC,RC);

double **AB  =            i_mR(RC,RC);

  rToeplitz_mR(U1,V1,A);
  rToeplitz_mR(U2,V2,B);
  
  clrscrn();
  printf(" The circulant matrices are commutative\n\n\n"
         " A: Toeplitz matrix");
  p_mR(A, S4,P0,C10);

  printf(" B: Toeplitz matrix");
  p_mR(B, S4,P0,C10);
  stop();
  
  clrscrn();
  printf(" The circulant matrices are commutative\n\n\n");
  printf(" AB:");
  p_mR(mul_mR(A,B,AB), S8,P0,C6);
  printf(" BA:");
  p_mR(mul_mR(B,A,AB), S8,P0,C6);
  stop();
      
  f_mR(U2);
  f_mR(V2);  
  f_mR(U1);
  f_mR(V1);   
  f_mR(A);
  f_mR(B);
  f_mR(AB);  
    
  return 0;
}
/* ------------------------------------ */
/* ------------------------------------ */


Screen output example:

                                                                                       
 The circulant matrices are commutative


 A: Toeplitz matrix
  +1   +2   +3   +4   +5   +6 
  +6   +1   +2   +3   +4   +5 
  +5   +6   +1   +2   +3   +4 
  +4   +5   +6   +1   +2   +3 
  +3   +4   +5   +6   +1   +2 
  +2   +3   +4   +5   +6   +1 

 B: Toeplitz matrix
  +7   +5   +6   +8   +9   +4 
  +4   +7   +5   +6   +8   +9 
  +9   +4   +7   +5   +6   +8 
  +8   +9   +4   +7   +5   +6 
  +6   +8   +9   +4   +7   +5 
  +5   +6   +8   +9   +4   +7 

 Press return to continue. 


 The circulant matrices are commutative


 AB:
    +134     +143     +146     +137     +122     +137 
    +137     +134     +143     +146     +137     +122 
    +122     +137     +134     +143     +146     +137 
    +137     +122     +137     +134     +143     +146 
    +146     +137     +122     +137     +134     +143 
    +143     +146     +137     +122     +137     +134 

 BA:
    +134     +143     +146     +137     +122     +137 
    +137     +134     +143     +146     +137     +122 
    +122     +137     +134     +143     +146     +137 
    +137     +122     +137     +134     +143     +146 
    +146     +137     +122     +137     +134     +143 
    +143     +146     +137     +122     +137     +134 

 Press return to continue.