# C and C++ library of functions and procedures for matrix (bidimensional arrays) processing – Introduction

#### Library source: C and C++ library of functions and procedures for matrix processing

Language: C / C++
Date: 04.2002
Authors: Catalin Boja si Niculescu Silviu

This post main objective is to tackle a series of aspects regarding the creation of a library that contains functions necessary in resolving the problems with matrices.

First chapters are containing initialization, listing on screen and computing subprograms. The last ones present this problem objective approach.

It has been created a library specialized in matrix computation that it is used for resolving real life problems.

As this paper main approach is the matrix processing, it will be made some references that will help the user understanding this text and the programs.

Many economic problems use representations of homogeneous data that are corresponding one-dimensional, two-dimensional and multidimensional structures. Matrix computation has a special place in resolving those problems. Problems of balance sheet are resolved with the help of matrix. Problems of the balance between economic branches are resolved too, with the help of matrix. Also the field of operational research uses the technological matrix. Linear programming supposes the work with the method of quadrangle. In econometrics, the regression method uses expressions of matrix computation.

In the functions library named matrix.h, a matrix is declared with the help of the variable X. The lines number of this matrix is memorized by the integer variable n, and the columns number is represented also by an integer variable named in this case m. To run through the matrix it has been used as counters the variables i and j, and when are necessary more than two counter variables, the characters k and l are also representing variables. Many subprograms from the library matrix.h are getting the parameters in this succession: lines number, columns number and the matrix; that is n, m, X. The parameters transfer out from the function is made usually using their value. In case these rules are not respected, the source text of the subprogram gives any necessary explication.

The matrix class is implementing the dynamic method of using matrices. The two-dimensional matrix is declared with the variable a. This variable can be accessed only inside the class because its implicit characteristic is private. The lines number and the columns number are also represented by the variables n and m. For a good view of the source text and for not writing them in each function’ body, the variables i and j, used as counters, have been declared inside the class.

Both the library matrix.h and the class matrix are written in the C++ language, being implemented in Borland C++ for Windows. If this code is used for developing applications in other IDEs, like Visual Studio, you must pay attention to the particularities that appear when using the DOS function clrscr() (The simplest way to change the library is to remove the clrscr() calls).

This project implements two different methods that can be used in applications with matrices. The static one is implemented in the library matrix.h and the dynamic one is in the class matrix. In the dynamic variant the memory size and the user’s experience are giving the restrictions regarding the matrix dimensions. On the other hand, in the other variant, a two-dimensional matrix could have maximum 30 lines and 30 columns and a one-dimensional one could have 1000 components.

A matrix defined static looks like this :

```int x;
```

Using the dynamic method, a matrix is defined in this way:

```int **a;
```
• dynamic memory allocation for an array of pointers
• the components of the pointers’ array are initialized with corresponding memory addresses of a matrix line.

The memory allocation is done by a class matrix member function, which is presented in detail in the chapter In and out functions. Also, in this chapter are described the class constructors.

Going through a matrix defined with the static method is done using the instructions:

`for (i=0;i<n;i++) for(j="0;j<m;j++)" <="" pre="">`

In the dynamic variant, the memory allocation for the two-dimensional matrix is realized using only one instruction for.

```int **pmat=(int **)malloc(n*sizeof(int*));
for (int i=0;i<n;i++) pmat[i]="(int*)malloc(m*sizeof(int))" <="" pre="">```

For the reason of compatibility, inside the friend and member functions the matrix crossing is made as in the static method.

With the hope that all this information will help the good understanding of this project contents, the authors are grateful to all whom through their observations and suggestions will have any contributions in improving their work.

`</n;i++)>`
`</n;i++)>`