Thread: comparing two matrices or double values

  1. #1
    Registered User
    Join Date
    Mar 2005
    Posts
    17

    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. #2

  3. #3
    Registered User
    Join Date
    Mar 2005
    Posts
    17
    Lookin good now thanks.

  4. #4
    Senior Member joshdick's Avatar
    Join Date
    Nov 2002
    Location
    Phildelphia, PA
    Posts
    1,146
    You're welcome.

  5. #5
    Registered User
    Join Date
    Mar 2005
    Posts
    17

    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 subscribe to a feed

Similar Threads

  1. C++ to C Conversion
    By dicon in forum C Programming
    Replies: 7
    Last Post: 06-11-2007, 08:38 PM
  2. expected primary expression
    By mju4t in forum C Programming
    Replies: 2
    Last Post: 03-27-2007, 06:59 PM
  3. Certain functions
    By Lurker in forum C++ Programming
    Replies: 3
    Last Post: 12-26-2003, 01:26 AM
  4. error message, what does it mean?
    By Shy_girl_311 in forum C++ Programming
    Replies: 5
    Last Post: 11-09-2001, 09:54 PM
  5. Hi, could someone help me with arrays?
    By goodn in forum C Programming
    Replies: 20
    Last Post: 10-18-2001, 09:48 AM