## Matrices (Part 1)

This post is heading a planned series of matrices related posts. Matrices are extremely usefull for programming advanced functions that can be used in sound and graphic appplications as well as for managing complex physical process. This first post starts with the basics which are required to build an efficient library.

Firstly, what is a matrix? It is nothing else than a two dimensional table containing data. In the C world, tables are in fact memory spaces which contain sequentially recorded data, so that managing tables imposes the use of separate variables which contain the number of rows and columns for a specific table.

Fortunately, universal conventions apply to the naming of matrices, columns and rows identification.

• The m variable applies to the number of rows, while the i variable applies to one specific colmun index
• The n variable applies to the number of columns, while the j variable applies to one specific colmun index
• As a consequence, A[i*m, j] is the name of one specific cell from the matrix
• C language fails to provide size information reltaed to one vector of data, so that we have two options for managing matrices within the library. We could set matrix parameters appart from each other e.g. of function used for building a unit matrix:

```unit(double* vector, uint8_t rows, uint8_t cols){};
```

but this option leads to a more complex code than the second option which consists in using objects. The struct record type which aggregates a fixed set of labelled objects, possibly of different types, into a single object, such as:

```struct varMat{
uint8_t m; /* nbr of rows */
uint8_t n; /* nbr of columns */
double *v; /* vector of data */
};
```

The same unit function becomes

```unit(struct varMat* mA) {};
```

Warning: The varMat record type should not be declared within the normal .h header file (e.g. PlainMAT.h). It must be declared in a separate .h file ! Check this thread

Next post on same subject

### One Comment

1. […] Previous post on same subject […]