matrix inversion

Discussion in 'Mac Programming' started by farmerdoug, Dec 31, 2008.

  1. farmerdoug macrumors 6502a

    Joined:
    Sep 16, 2008
    #1
    From Xcode documentation
    InverseMatrix
    Creates a new matrix that is the inverse of a specified matrix.

    Boolean InverseMatrix (
    const MatrixRecord *m,
    MatrixRecord *im
    );

    and

    MatrixRecord
    Contains a transformation matrix.

    struct MatrixRecord {
    Fixed matrix[3][3];
    };

    but this is not enough information for me to invert a matrix. I can define matrices and fill them but I can't call InverseMatrix properly.
    One attempt which didn't work

    #include <iostream>
    #include "function.h"
    #include <ImageCompression.h>

    int main (int argc, char * const argv[]) {
    // insert code here...
    int i, j;
    struct MatrixRecord {
    Fixed matrix[3][3];
    Fixed imatrix[3][3];
    } m;


    for (i = 0; i < 3; i++)
    for(j=0; j<3; j++)
    m.matrix[j] = i*j;
    InverseMatrix( m.matrix, m.imatrix);
    return 0;
    }

    Error cannot convert Fixed (*)[3] to const MatrixRecord*

    No surprise there

    help.
    thanks.
     
  2. Sander macrumors 6502

    Joined:
    Apr 24, 2008
    #2
    You are redefining the MatrixRecord struct, which is probably not what you should be doing. Instead, try this:

    Code:
    MatrixRecord m;
    MatrixRecord im;
    
    for (i = 0; i < 3; i++)
      for(j=0; j<3; j++)
        m.matrix[i][j] = i*j;
    
    InverseMatrix(&m, &im);
    
     
  3. farmerdoug thread starter macrumors 6502a

    Joined:
    Sep 16, 2008
    #3
    matrices

    But that by itself doesn't work. Don't I have to allocate memory for m and im?
     
  4. farmerdoug thread starter macrumors 6502a

    Joined:
    Sep 16, 2008
    #4
    matrix continued

    I got it to compile but when I run it, I find that I can't load values into m.matrix and I get an Abort trap. Running it without the first print gives me an abort trap with the message that _InverseMatrix is an unknown symbol.

    #include <iostream>
    #include <ImageCompression.h>
    int main (int argc, char * const argv[]) {
    // insert code here...
    MatrixRecord m;
    MatrixRecord im;
    int i,j;


    for (i = 0; i < 3; i++)
    for(j=0; j<3; j++)
    m.matrix[j] = i*j;
    for (i = 0; i < 3; i++)
    for(j=0; j<3; j++)
    printf("%f ", m.matrix[j]);


    InverseMatrix(&m, &im);
    for (i = 0; i < 3; i++)
    for(j=0; j<3; j++)
    printf("%f ", im.matrix[j]);

    return 0;
    }
     
  5. Sander macrumors 6502

    Joined:
    Apr 24, 2008
    #5
    No, these are ordinary strucs which live on the stack. If this sounds like Greek to you, don't hesitate to ask for a clarification...
     
  6. Sander macrumors 6502

    Joined:
    Apr 24, 2008
    #6
    This probably means the correct library wasn't found. I'm not on my Mac right now, so I'm afraid I can't tell you which library this function is in...
     

Share This Page