This is the mail archive of the gsl-discuss@sources.redhat.com mailing list for the GSL project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Howto make a cross prod with gsl ?


Jean-Max Redonnet writes:
 >  I'm a new user of gsl I will try to use for differential geometry
 > computations.  Maybe I'm wrong, but I've not found a prebuilt
 > function to perform cross product between vectors... ...so I've
 > write one : This works fine, but I wonder if there is a best way to
 > do that.

Hi, 

For small vectors it will be faster to keep the components on the
stack as an ordinary array, rather than using malloc to create a
gsl_vector object.  

If you need to pass the array to a gsl_linalg function you can use the
gsl_vector_view_array() function to create a temporary view.

e.g. This is how I would do it,

#define X 0
#define Y 1
#define Z 2

int main () {
  double p[3] = {1, 0, 0}, q[3] = {0, 1, 0}, r[3] ;
  
  cross(p, q, r);
}

void cross (const double * a, const double * b, double * v)
{
  v[X] = a[Y] * b[Z] - a[Z] * b[Y];
  ....
}

regards
Brian


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]