The Matrix Module

The Matrix Object

Topics:

How to create a matrix or vector

Types of matrices and vectors

References

Further information about the module:


How to create a matrix or vector

You define a matrix or a vector by typing the object type followed by the name of the new object. As you will see in detail in the next section there are a couple of types for matrices as well as for vectors. As an example we define a 0x0 matrix m with float coefficients (The following examples are using the float matrix type FMatrix. The principles are the same for other matrix and vector types).
% FMatrix m
m
By adding another 2 arguments we can specify the dimensions of the matrix (If you really try this use another name since you cannot define the same matrix again until you have destroyed it).
% FMatrix m 3 3
m
We can also define the whole matrix with all its coefficients by using { } to structure the input.
% FMatrix m {{1 2} {3 4} {5 6}}
m
The contents of a matrix can by shown be simply typing the name of the object.
% m
{  1.0000e+00  2.0000e+00 }
{  3.0000e+00  4.0000e+00 }
{  5.0000e+00  6.0000e+00 }
Instead of giving the coefficients directly you can also use the name of another matrix or read the coefficients from a file.
% FMatrix m1 another_matrix
m1
% FMatrix m2 @name_of_the_file
m2 
As already mentioned above you can only define a matrix once. If you want to change the contents you have to destroy the matrix and redefine it or use a matrix method like ':=' to change the coefficients.
% destroy m1
% FMatrix m1 {{1 2 3}}
m1
% m2 := m1
A nice Tcl trick is to use the return value of a definition, which is the name of the new object, as a command by adding a matrix method. This way you can for example load data from a binary matrix file with one Tcl line.
% [FMatrix m] bload filename

Types of matrices and vectors

There are different types of matrices and vectors. The first letter of the type name indicates how coefficients are represented in the machine followed by either Matrix, Vector or variants like BMatrix. The different object types might have some identical methods but others are specific for the type. For example there is no eigenvalue method for IMatrix but for DMatrix objects.
However, you can convert some of the types into each other.
% #--- converting a float matrix f into a double matrix d ---
% d FMatrix f

References:

[1] Bronstein; Semendjajew: Taschenbuch der Mathematik; Verlag Harry Deutsch

[2] G. Fischer: Lineare Algebra; Vieweg & Sohn


maier@ira.uka.de