Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

farmerdoug

macrumors 6502a
Original poster
Sep 16, 2008
541
0
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.
 

Sander

macrumors 6502a
Apr 24, 2008
521
67
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);
 

farmerdoug

macrumors 6502a
Original poster
Sep 16, 2008
541
0
matrices

But that by itself doesn't work. Don't I have to allocate memory for m and im?
 

farmerdoug

macrumors 6502a
Original poster
Sep 16, 2008
541
0
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;
}
 

Sander

macrumors 6502a
Apr 24, 2008
521
67
But that by itself doesn't work. Don't I have to allocate memory for m and im?

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

Sander

macrumors 6502a
Apr 24, 2008
521
67
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.

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...
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.