-1

I have two vectors, x, y and I need to get outer product i.e xy'. I have to do this in GSL library and I am not sure if there is a function to do it.

Can anyone tell me if there is a function or procedure to calculate the outer product in GSL?

Morpheus
  • 3,285
  • 4
  • 27
  • 57

3 Answers3

1

I believe the function you are looking for is in the BLAS interface, which has the following prototype:

int gsl_blas_dsyr(CBLAS_UPLO_t Uplo, double alpha, const gsl_vector * x, gsl_matrix * A

This function sends A -> A + alpha x x'. To calculate the outer product, take the case alpha = 1, and A=0. Note, that Uplo = CblasUpper specifies that, since A is symmetric, only the upper-triangular entries are computed. If you want the full matrix, be sure to symmeterize after. So,

int outerProduct(gsl_matrix* A, const gsl_vector *x, const int len){
  A = gsl_matrix_calloc(len,len);
  return gsl_blas_dsyr(CblasUpper,1.0,x,A);
}

will allocate a len by len matrix, and, assuming x is of length len, will produce the outer-product into the upper-triangular portion of A.

1

I'd use function

int gsl_blas_dger(double alpha, const gsl_vector * x, const gsl_vector * y, gsl_matrix * A)

The function sends A -> A + alpha x y'.

papgeo
  • 427
  • 3
  • 13
0
cross(v0,v1) 

The "outer product" in 2D, is the same as the cross product, despite Z not being really defined.

See http://allenchou.net/2013/07/cross-product-of-2d-vectors/

Also, note that the result will be:

  • scalar as the outer product of 2D vectors,
  • vector as the outer product of 3D vectors.
Marcin Wasiluk
  • 4,675
  • 3
  • 37
  • 45
3Dave
  • 28,657
  • 18
  • 88
  • 151