# Thread: comparing two matrices or double values

1. ## comparing two matrices or double values

I'm trying to compare two matrices to see if they are equal. They are stored in the same manner, in that I use a double pointer.

This is my code

Code:
``` for ( row = 0; row < rows; ++row )
{
for ( col = 0; col < cols; ++col )
{
int i = col * rows + row;
if(matrixD[i] != matrixC[i])
{
printf("matrixd, %8g, matrixC, %8g \n", matrixD[i], matrixC[i]);
flag = TRUE;
return flag;
}
}
}```
This gives me a result

matrixd, 21.544, matrixC, 21.544
The results are NOT equal!!
They seem to be the saem so should I be using some sort of comparison function. Somebody said maybe use L2Same - what is it and does anyone know how i would use it?

Thanks,

Colly.

2. Lookin good now thanks.

3. You're welcome.

4. ## It was working...

It was working fine like this:

Code:
```boolean compare_matrices(double *matrixC, double *matrixD, int rows, int cols)^M
{
const double EPSILON = 0.0000000001;
int row, col;
boolean flag = FALSE;
for ( row = 0; row < rows; ++row )
{
for ( col = 0; col < cols; ++col )
{
int i = col * rows + row;
/* if((int)matrixD[i] != (int)matrixC[i]) */
if ( fabs(matrixD[i] - matrixC[i]) > EPSILON)
{
printf("matrixd, %8g, matrixC, %8g \n", matrixD[i], matrixC[i]);
flag = TRUE;
return flag;
}
}
}
return flag;
}```
I was using a gcc compiler but needed to switch to an openMP enabled compiler - pgcc from the portland group. But now this doesn't work. Would I need to use some compiler flags here or something?

Thanks,

Colly.

Popular pages Recent additions