views:

38

answers:

1

Dear all, I have a 2 by 2 square matrix with real intries that I want to pass to a method. It looks as;

 double coefficients[2][2] = { { 1.00, 0.6789140 }, {0.4446350, 0.4301290 } };

 [self PrintOut:?????? andNRows:2 andNColumns:2];

- (void) PrintOut:(double ?????? andNRows:(NSInteger)rows andNColumns:(NSInteger)columns {

 // do something here
}

can somebody let me know please how should I pass it so that I can retrieve the entries either as coefficients[ i ][ j ] or coefficients[ i * rows + j ]?

A: 

Some books I have suggest passing this in as a one dimensional array then accessing the rows and columns like matrix[(i*rows) + j]. You could then create a class to contain the matrix which would provide a method that just wraps that with something taking i and j as arguments if you want, then another method just taking a single i index into the array.

You might also use a macro.

Unfortunately there's no operator overloading in objective C so you can't overload [] or something.

Nimrod