thank you,
my question actually was about how to pass multi dim arrays (matrices) to a function and get multi-dim arrays (matrices) back to the calling function, not about this #define thing (I know I have to use malloc in C - this #define ArrayBuild construct of course was only needed for NXC because there was no other way in NXC to do it C-like).
I had a look at the gsl lib, but I'm not sure about what a gsl matrix is, to me a 2-dim array (matrix) is sth like float or int a[][]
The documentation gives information just about
8.4.10 Matrix operations
The following operations are defined for real and complex matrices.
Function: int gsl_matrix_add (gsl_matrix * a, const gsl_matrix * b)
This function adds the elements of matrix b to the elements of matrix a. The result a(i,j) \leftarrow a(i,j) + b(i,j) is stored in a and b remains unchanged. The two matrices must have the same dimensions.
Function: int gsl_matrix_sub (gsl_matrix * a, const gsl_matrix * b)
This function subtracts the elements of matrix b from the elements of matrix a. The result a(i,j) \leftarrow a(i,j) - b(i,j) is stored in a and b remains unchanged. The two matrices must have the same dimensions.
Function: int gsl_matrix_mul_elements (gsl_matrix * a, const gsl_matrix * b)
This function multiplies the elements of matrix a by the elements of matrix b. The result a(i,j) \leftarrow a(i,j) * b(i,j) is stored in a and b remains unchanged. The two matrices must have the same dimensions.
Function: int gsl_matrix._div_elements (gsl_matrix * a, const gsl_matrix * b)
This function divides the elements of matrix a by the elements of matrix b. The result a(i,j) \leftarrow a(i,j) / b(i,j) is stored in a and b remains unchanged. The two matrices must have the same dimensions.
Function: int gsl_matrix_scale (gsl_matrix * a, const double x)
This function multiplies the elements of matrix a by the constant factor x. The result a(i,j) \leftarrow x a(i,j) is stored in a.
Function: int gsl_matrix_add_constant (gsl_matrix * a, const double x)
This function adds the constant value x to the elements of the matrix a. The result a(i,j) \leftarrow a(i,j) + x is stored in a.
I can't find more detailed information about how to use a general formula to multiply a NxM matrix by a MxK matrix, and I'm completely missing informations about determinants, adjugates, inverse, and rotation.
So I think I'll have to write it on my own, and for the first step I'll need to know how to make this sort of thing:
Code: Select all
void MatrixMatrixMult(float A[][], float B[][], float &C[][], int N, int M, int K)
all matrices must be able to be passed at any size, so the function must work for multiplying
2x3 by 3x5 (returns a 2x5 matrix)
as well as for 2x2 by 2x2 (returns a 2x2 matrix)
or 2x3 by 3x2 (returns also a 2x2 matrix).
The function call should be like I did it in the former task main():
Code: Select all
task main() {
float A[2][2], B[2][2], C[2][2];
A[0][0]=1; A[0][1]=3;
A[1][0]=2; A[1][1]=4;
B[0][0]=10; B[0][1]=30;
B[1][0]=20; B[1][1]=40;
MatrixMatrixMult(A,B,C, 2,2,2); // C[2][2] will be the result matrix