Exemplo n.º 1
0
/*forms asymmetric matrix with the same lower triangular part*/
inline void asym(double* a,int n){
	int i;
	gsl_matrix_view av=gsl_matrix_view_array(a,n,n);
	for (i=1;i<n;i++){
		gsl_vector_view vsup=gsl_matrix_superdiagonal(&av.matrix,i);
		gsl_vector_view vsub=gsl_matrix_subdiagonal(&av.matrix,i);
		gsl_vector_memcpy(&vsup.vector,&vsub.vector);
		gsl_vector_scale(&vsup.vector,-1);
	}
	gsl_vector_view vsup=gsl_matrix_superdiagonal(&av.matrix,0);
	gsl_vector_set_zero(&vsup.vector);
}
Exemplo n.º 2
0
	Vector Matrix::superdiagonalVector ( const size_t offset ) {
		// To circumvent GSL limitation to allow 0-dimensional vectors
		// This use of static data relies on the immutability of 0-dim Vectors.
		static Vector nullDimVector( 0, NULL, 0 );
		if ( 0 == countRows() ) return nullDimVector;
		return Vector( gsl_matrix_superdiagonal( &matrix, offset ) );
	}
Exemplo n.º 3
0
int
gsl_multifit_linear_Lk(const size_t p, const size_t k, gsl_matrix *L)
{
  if (p <= k)
    {
      GSL_ERROR("p must be larger than derivative order", GSL_EBADLEN);
    }
  else if (k >= GSL_MULTIFIT_MAXK - 1)
    {
      GSL_ERROR("derivative order k too large", GSL_EBADLEN);
    }
  else if (p - k != L->size1 || p != L->size2)
    {
      GSL_ERROR("L matrix must be (p-k)-by-p", GSL_EBADLEN);
    }
  else
    {
      double c_data[GSL_MULTIFIT_MAXK];
      gsl_vector_view cv = gsl_vector_view_array(c_data, k + 1);
      size_t i, j;

      /* zeroth derivative */
      if (k == 0)
        {
          gsl_matrix_set_identity(L);
          return GSL_SUCCESS;
        }

      gsl_matrix_set_zero(L);
  
      gsl_vector_set_zero(&cv.vector);
      gsl_vector_set(&cv.vector, 0, -1.0);
      gsl_vector_set(&cv.vector, 1, 1.0);

      for (i = 1; i < k; ++i)
        {
          double cjm1 = 0.0;

          for (j = 0; j < k + 1; ++j)
            {
              double cj = gsl_vector_get(&cv.vector, j);

              gsl_vector_set(&cv.vector, j, cjm1 - cj);
              cjm1 = cj;
            }
        }

      /* build L, the c_i are the entries on the diagonals */
      for (i = 0; i < k + 1; ++i)
        {
          gsl_vector_view v = gsl_matrix_superdiagonal(L, i);
          double ci = gsl_vector_get(&cv.vector, i);

          gsl_vector_set_all(&v.vector, ci);
        }

      return GSL_SUCCESS;
    }
} /* gsl_multifit_linear_Lk() */