Google

Matrix Library

© Anton Voronin (anton@urc.ac.ru), 1996-1997

This library lets to manipulate matrices and vectors. To use it you have to include its header file matrix.h. It defines the base class MATRIX and derived class VECTOR.

Class MATRIX comtains the following methods:

  • unsigned Height( void ) - get the number of matrix rows;
  • unsigned Length( void ) - get the number of matrix columns;
  • double Element( int column, int row ) - get the value of element specified by column and row;
  • double Element( int column, int row, double value ) - assign the value to the element specified by column and row;
  • "*" - multiplicate by another matrix or a scalar;
  • "+" - add with another matrix;
  • "-" - substract another matrix;
  • Unary "-" - negate the matrix;
  • "^" - concatenate with another matrix from the left;
  • Unary "~" - invert the matrix;
  • Unary "!" - transposition the matrix;
  • "/" - divide the matrix by a scalar;
  • "=" - assign the matrix with another matrix;
  • MATRIX MatrAbs( void ) - makes all the matrix elements to have absolute values;
  • double GetNorm00( void ) - compute the norm of the matrix;
  • double GetNorm2( void ) - Euclide norm computation;
  • MATRIX ChangeCols( unsigned column1, unsigned column2 ) - exchange matrix columns;
  • MATRIX ChangeRows( unsigned row1, unsigned row2 ) - exchange matrix rows;
  • MATRIX InitObject( FILE *fp ) - initialize the matrix with values from the specified file;
  • void FPrintObject( FILE *fp ) - print the matrix values out to the specified file;
Class VECTOR has additional methods:
  • unsigned Dim( void ) - get the number of vector's elements;
  • double Element( int element ) - get the value of the vector element;
  • double Element( int element, double value ) - assign the value to the vector element;
  • "," - scalar multiplication by another vector;
You can create MATRIX or VECTOR object either by initializing it with another object:
	MATRIX m1=m2;
	VECTOR v1=v2;
	MATRIX m3=v1;	// creates single-column matrix from the vector
	VECTOR v3=m1;	// if m1 consist of a single column or a single row,
			// creates vector from it, else generates error
	double num=12345.6578;
	MATRIX m1=num;	// creates 1x1 matrix and assigns the value of number
			// to its only element
or without initialization, by only specifying number of cols and rows for MATRIX object or vector length for VECTOR object:
	MATRIX m1(10,15);
	VECTOR v1(8);
You can also use the following type casting operations:
  • VECTOR() - cast to a vector;
  • MATRIX() - cast to a matrix;
  • double() - cast to a scalar;
The program that wants to use this library has to define the following functions:
  • void quit( void );

    should perform a normal program termination (in most cases it may just wrap to exit() in case of MS-DOS or Unix or PostQuitMessage() in case of Windows).

  • void errmes( char * );

    should somehow make the given string visible to a user (in most cases it may be just a wrapper for printf() in case of MS DOS or UNIX or mess() from the Message Library in case of MS DOS, or DialogBox() in case of Windows)


Download