help-gsl
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Help-gsl] Find variance - covariance matrix of a matrix


From: Churna Bhandari
Subject: Re: [Help-gsl] Find variance - covariance matrix of a matrix
Date: Thu, 11 Mar 2010 13:28:29 -0700

Hi

Thanks. I am sorry i mistakenly put different question here. After taking
derivative of absolute value function, I will have expression with step
function.I have to integrate the expression which contains step function as
follows

int_{0}^{infty} g(x)[theta(f(x))-theta(-f(x))] dx

here argument of theta is function f(x). If there is already developed
routine for such integral it would be preety simple for me. If i simply
analyze  I notice limit of integration is zero to infity. But argument of
theta function selects new limit for the integration. So I have difficulty
writing code for this step.
Thank you

suvas



On Thu, Mar 11, 2010 at 6:35 AM, kamaraju kusumanchi <
address@hidden> wrote:

> To evaluate the absolute value, you can use fabs in <math.h>. It is
> part of standard C (no gsl needed). Is that what you are looking for
> or did I miss something?
>
> raju
>
> On Tue, Mar 9, 2010 at 10:53 AM, Churna Bhandari <address@hidden>
> wrote:
> > Hi
> > Please, can anyone suggest me i have no idea how to integrate for the
> > absolute value function. Is there any gsl routine for absolute function
> > integration written in c language? I would be happy if anyone help me.
> > Thanks,
> > suvas
> >
> > On Tue, Mar 9, 2010 at 3:20 AM, Francesco Abbate <
> address@hidden>wrote:
> >
> >> 2010/3/9 Srimal Jayawardena <address@hidden>:
> >> > Hi
> >> >
> >> > Is there a simple function/method for me to obtain the variance -
> >> > covariance matrix of a given matrix.
> >> >
> >> > I'm looking for the  equivalent of 'cov' in MATLAB
> >>
> >> Here what the Matlab documentation says:
> >>
> >> ------
> >> C = cov(x) where x is a vector returns the variance of the vector
> >> elements. For matrices where each row is an observation and each
> >> column a variable, cov(x) is the covariance matrix. diag(cov(x)) is a
> >> vector of variances for each column, and sqrt(diag(cov(x))) is a
> >> vector of standard deviations.
> >> ------
> >>
> >> So actually what Matlab calculates is the covariance between each of
> >> the column vectors.
> >>
> >> Here a simple routine that, given a matrix m, calculates the
> >> covariance matrix by in the matrix r.
> >>
> >> void
> >> cov_calculate(gsl_matrix *r, gsl_matrix *m)
> >> {
> >>  gsl_vector_view a, b;
> >>  size_t i, j;
> >>
> >>  for (i = 0; i < m->size1; i++) {
> >>    for (j = 0; j < m->size2; j++) {
> >>      double v;
> >>      a = gsl_matrix_column (m, i);
> >>      b = gsl_matrix_column (m, j);
> >>      v = gsl_stats_covariance (a.vector.data, a.vector.stride,
> >> b.vector.data, b.vector.stride, a.vector.size);
> >>      gsl_matrix_set (r, i, j, v);
> >>    }
> >>  }
> >> }
> >>
> >> Note that the function gsl_stats_covariance does not works with
> >> vectors or matrices but only with double pointer. This is why we need
> >> to take directly the "data" field of the vector struct.
> >>
> >> Best regards,
> >> Francesco
> >>
> >>
> >> _______________________________________________
> >> Help-gsl mailing list
> >> address@hidden
> >> http://lists.gnu.org/mailman/listinfo/help-gsl
> >>
> > _______________________________________________
> > Help-gsl mailing list
> > address@hidden
> > http://lists.gnu.org/mailman/listinfo/help-gsl
> >
>


reply via email to

[Prev in Thread] Current Thread [Next in Thread]