Tcl procedures to create, access and manipulate the Matrix object

Tcl procedures to create, access and manipulate the Matrix object


set_matrix_size
create_matrix
initialise_matrix
get_matrix_element
get_matrix_dimensions
set_matrix_element
print_matrix
diagonalise_matrix
invert_matrix
multiply_matrix
add_matrix
subtract_matrix
upscale_matrix
downscale_matrix
assign_matrix
transpose_matrix
symmetrize_matrix
copy_matrix

set_matrix_size

Arguments:

 matrix          c matrix tag                                                             
 datatype        c keyword              data type - must be real                          
 dimensions      c list of 2 integers                                                     
 name            c text                 descriptive text string                           
Allocate memory for a matrix object

create_matrix

Arguments:

 matrix          c matrix tag           denotes matrix to create                          
 datatype        c keyword              data type - must be real                          
 dimensions      c list of 2 integers                                                     
 name            c text                 descriptive text string                           
 final arg       c text                 input data                                        
Create a matrix object, includes allocation of the memory and input of the data. The final argument is the data, e.g:
  create_matrix matrix=a datatype=real dimensions= {4 4} name=A {
  1. 0. 0. 2.
  0. 1. 0. 0.
  0. 0. 1. 0.
  3. 0. 0. 1.
  }
  

initialise_matrix

Arguments:

 matrix          c matrix tag           denotes matrix to create                          
 datatype        c keyword              data type - must be real                          
 dimensions      c list of 2 integers                                                     
 name            c text                 descriptive text string                           
Create a matrix object, and set all elements to zero.
  initialise_matrix matrix=a datatype=real dimensions= {4 4} name=A
  

get_matrix_element

Arguments:

 matrix          c matrix tag           denotes matrix to interrogate                     
 format          f text                 output format e.g. %12.5f                         
 indices         c list of 2 integers   which element to output                           
Return value of an element of a matrix, e.g.
  set a [ get_matrix_element matrix=a indices= {1 1} format=%12.5f ]
  

get_matrix_dimensions

Arguments:

 matrix          c matrix tag           denotes matrix to interrogate                     
Return the dimensions of a matrix, as a Tcl list of 2 integers.

set_matrix_element

Arguments:

 matrix          c matrix tag           denotes matrix to modify                          
 indices         c list of 2 integers   which element to output                           
 value           c real                 value to assign                                   
Assign an element of a matrix.

print_matrix

Arguments:

 matrix          c matrix tag           denotes matrix to create                          
 value           c real                 value to assign                                   
 rows            o range                which rows to print (default all)                 
 columns         o range                which columns to print (default all)              
Assign an element of a matrix.

diagonalise_matrix

Arguments:

 matrix          c matrix tag           denotes matrix to diagonalise                     
 evals           c matrix tag           matrix to hold eigenvalues (will be created)      
 evecs           c matrix tag           matrix to hold eigenvectors (will be created)     
Diagonalise a matrix.

invert_matrix

Arguments:

 matrix          c matrix tag           denotes matrix to diagonalise                     
 result          c matrix tag           matrix to hold inverse (will be created)          
Invert a matrix.

multiply_matrix

Arguments:

 left            c matrix tag           left hand matrix                                  
 right           c matrix tag           right hand matrix                                 
 result          c matrix tag           result matrix (will be created)                   
Multiplication of 2 matrices.

add_matrix

Arguments:

 left            c matrix tag           left hand matrix                                  
 right           c matrix tag           right hand matrix                                 
 result          c matrix tag           result matrix (will be created)                   
Addition of 2 matrices.

subtract_matrix

Arguments:

 left            c matrix tag           left hand matrix                                  
 right           c matrix tag           right hand matrix                                 
 result          c matrix tag           result matrix (will be created)                   
Subtraction of 2 matrices.

upscale_matrix

Arguments:

 matrix          c matrix tag           input matrix                                      
 factor          c real                 scale factor                                      
 result          c matrix tag           result matrix (will be created)                   
Multiplication of a matrix by a constant

downscale_matrix

Arguments:

 matrix          c matrix tag           input matrix                                      
 factor          c real                 scale factor                                      
 result          c matrix tag           result matrix (will be created)                   
Division of a matrix by a constant

assign_matrix

Arguments:

 from            c matrix tag           input matrix                                      
 to              c real                 scale factor                                      
 row_mapping     o Tcl list of integers rows to assign to                                 
 column_mapping  o Tcl list of integers columns to assign to                              
Assign_matrix copies the data values from a matrix to another matrix. The optional column_mapping and row_mapping arguments specify the destination row/column in the "to" matrix for each row/column in the "from" matrix. The result matrix must exist and have the correct dimensions.
  assign_matrix from=a to=b column_mapping= {1 2 3} row_mapping= {4 3 2 1}
  

transpose_matrix

Arguments:

 matrix          c matrix tag           input matrix                                      
 result          c matrix tag           result matrix (will be created)                   
Matrix transposition.

symmetrize_matrix

Arguments:

 matrix          c matrix tag           input matrix                                      
 result          c matrix tag           result matrix (will be created)                   
Matrix symmetrization

copy_matrix

Arguments:

 from            c matrix tag           input matrix                                      
 to              c matrix tag           result matrix (will be created)                   
Copy a matrix