R
robix
Hi again. I'm now asking your help because of a smal problem i'm getting
with my multiplication matrix code.
I'll try to give you as many details as possible.
My matrix structure:
typedef struct {
int col; /* number of colowns */
int lin; /* number of lines*/
double *element; /* pointer do double... this is actually, a "simulated
multidymensional array", got the idea from the C FAQ from this newsgroup */
} matrix;
matrix mul_matrix(matrix mat1, matrix mat2, int lin, int col)
{
matrix M;
int i, j, k, exp;
M = init_matrix(lin, col); /* inits M(will old the result from mat1 *
mat2), no problem here. At this point i am sure that mat1 and mat2 all have
their right values
and that M has the right size*/
/* Try to multiply */
for (i=0; i<lin; i++) {
for (j=0; j<col; j++) {
exp = 0;
for (k=0; k<col; k++) {
exp += mat1.element[i * (mat1.col * mat1.lin) + k]*
mat2.element[k * (mat2.col * mat2.lin) + j]; /* big problem... give me
random results*/
}
M.element[i * (lin * col) + j] = exp;
}
}
return M;
}
After 4 hours of trying to resolve this problem i'm exaust and in need for
some sleep
Maybe that will make me good cause i sinceriously can't
see the problem on the code! Until now i've only used printf to assist me as
a rudimentary debugger. I think i need something more powerfull but
gdb don't want to work with devc++...
Thanks to anyone who can help me out!
with my multiplication matrix code.
I'll try to give you as many details as possible.
My matrix structure:
typedef struct {
int col; /* number of colowns */
int lin; /* number of lines*/
double *element; /* pointer do double... this is actually, a "simulated
multidymensional array", got the idea from the C FAQ from this newsgroup */
} matrix;
matrix mul_matrix(matrix mat1, matrix mat2, int lin, int col)
{
matrix M;
int i, j, k, exp;
M = init_matrix(lin, col); /* inits M(will old the result from mat1 *
mat2), no problem here. At this point i am sure that mat1 and mat2 all have
their right values
and that M has the right size*/
/* Try to multiply */
for (i=0; i<lin; i++) {
for (j=0; j<col; j++) {
exp = 0;
for (k=0; k<col; k++) {
exp += mat1.element[i * (mat1.col * mat1.lin) + k]*
mat2.element[k * (mat2.col * mat2.lin) + j]; /* big problem... give me
random results*/
}
M.element[i * (lin * col) + j] = exp;
}
}
return M;
}
After 4 hours of trying to resolve this problem i'm exaust and in need for
some sleep
see the problem on the code! Until now i've only used printf to assist me as
a rudimentary debugger. I think i need something more powerfull but
gdb don't want to work with devc++...
Thanks to anyone who can help me out!