[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
## [Help-gsl] GSL_Matrix problem

**From**: |
Kris B |

**Subject**: |
[Help-gsl] GSL_Matrix problem |

**Date**: |
Tue, 01 Jun 2004 19:01:49 +0000 |

Dear All,

`I have a very simple problem but I do not get the code to work. I have no
``clue what is going wrong.
``In my function I pass a matrix (2 rows, 3 columns) and I just want to get
``the same matrix to be in the result. I know this example is very stupid but
``I just want to learn to work with the GSL_matrix structures.
`My basic matrix mat is
1 3 5
2 4 6
stored as a vector 1 2 3 4 5 6. (I use column -major order from S-plus)
Gridpoints1 represent the number of rows, Gridpoints2 the number of columns.
So my function call in Splus looks like this
.C("test", as.double(result), as.double(mat), as.integer(2), as.integer(3))
Can someone explain why my result is
1 2 3 4 5 0
instead of
1 2 3 4 5 6?
I tested several cases and there are always some zero's at the end? Why?
Here is my code:
#include <gsl/gsl_matrix.h>
void test(double* result, double* mat, int* gridpoints1, int* gridpoints2)
{
const int g1=*gridpoints1;
const int g2=*gridpoints2;
int i, j;
gsl_matrix * m = gsl_matrix_alloc(g1, g2);
for (i = 0; i < g1; i++)
for (j = 0; j < g2; j++)
gsl_matrix_set(m, i, j, mat[i*g1 + j]);
for (i = 0; i < g1; i++)
for (j = 0; j < g2; j++)
result[i*g1 + j]=gsl_matrix_get(m, i, j);
}
Thanks in advance,
Kris
_________________________________________________________________

`Best Restaurant Giveaway Ever! Vote for your favorites for a chance to win
``$1 million! http://local.msn.com/special/giveaway.asp
`

**[Help-gsl] GSL_Matrix problem**,
*Kris B* **<=**