gsl-shell-info
[Top][All Lists]
Advanced

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

Re: [Gsl-shell-info] matrix operations


From: Francesco Abbate
Subject: Re: [Gsl-shell-info] matrix operations
Date: Wed, 21 Nov 2012 22:20:50 +0100

2012/11/21 John Coppola <address@hidden>:
> hello,
>
> i have a couple of questions on some matrix operations that i could not
> figure out from the documentation...
>
> 1. is there a way to combine matrices?  for example in matlab you can
> combine two matrices with something like this...
>
>   A = [1 1; 1 1]
>   B = [2 2; 2 2]
>   C = [A B] ---> C = [1 1 2 2; 1 1 2 2]
>   C = [A;B] ---> C = [1 1; 1 1; 2 2; 2 2]
>
> ...is there an easy way to do this with GSL-shell?

Hi John,

actually there isn't a direct way to do it. You can obtain the same
results by doing something like;

C = matrix.alloc(2, 4)
matrix.set(C:slice(1,1,2,2), A)
matrix.set(C:slice(1,3,2,2), B)

It does work but it is not very handy. I was actually thinking to add
a specific function for this task. My idea was to introduce a pack
function that works like that:

matrix.pack {{A, B}}   -- gives [1 1 2 2; 1 1 2 2]
matrix.pack {{A}, {B}}   -- gives [1 1; 1 1; 2 2; 2 2]

As an extension the "pack" function should accept scalars. These
should be converted to diagonal matrices of appropriate size with all
diagonal elements equals. With this extension you can cover the most
common cases of block filled with zeros or with diagonal (unit)
matrices.

I think I will add this function before the final release of 2.2.0 but
I'm open to different ideas.

> 2. is there a built-in command to get the sum, average, and standard
> deviation of the elements of a matrix?

No. What prevented me to introduce such functions was that I had no
idea about how it should work wrt to columns or rows. For the other
side in GSL there are functions to performs the statistical
operations. I can imagine to use it like:

stats.mean(m:row(k)) -- returns the mean of the elements in a row
stats.variance(m:row(k)) -- returns the variance

Unfortunately the module with statistical functions is not yet
implemented but it is almost trivial to do and I can accept volunteers
:-)

Francesco



reply via email to

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