[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Help-gsl] How to make diagonal matrix from vector
From: |
James Bergstra |
Subject: |
Re: [Help-gsl] How to make diagonal matrix from vector |
Date: |
Tue, 6 Sep 2005 10:06:05 -0400 |
User-agent: |
Mutt/1.4.1i |
On Tue, Sep 06, 2005 at 05:11:50AM -0700, hariram subramanian wrote:
...
> In simple words, I want to make GSL work in the way as Matlab does with diag
> (X), where X is some vector.
You might try something like this:
gsl_matrix * my_diag_alloc(gsl_vector * X)
{
gsl_matrix * mat = gsl_matrix_alloc(X->size, X->size);
gsl_vector_view diag = gsl_matrix_diagonal(mat);
gsl_matrix_set_all(mat, 0.0); //or whatever number you like
gsl_vector_memcpy(&diag.vector, X);
return mat;
}
--
james bergstra
http://www-etud.iro.umontreal.ca/~bergstrj