MathGroup Archive 2004

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: matrix operations

  • To: mathgroup at smc.vnet.net
  • Subject: [mg46350] Re: [mg46329] matrix operations
  • From: Andrzej Kozlowski <akoz at mimuw.edu.pl>
  • Date: Mon, 16 Feb 2004 08:59:51 -0500 (EST)
  • References: <200402150319.WAA06236@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

On 15 Feb 2004, at 04:19, paolo tarpanelli wrote:

> If I have a matrix
>
> a={x[[1,1]],x[[1,2]],...,x[[1,n]]}
>     {x[[2,1]],x[[2,2]],...,x[[2,n]]}
>             .
>             .
>             .
>     {x[[m,1]],x[[m,2]],...,x[[m,n]]}
>
> how can I compute the difference between any element and the previous  
> for each column :
>
> aa={x[[2,1]]-x[[1,1]], x[[2,2]]-x[[1,2]],...,x[[2,n]]-x[[1,n]]}
>       {x[[3,1]]-x[[2,1]], x[[3,2]]-x[[2,2]],...,x[[3,n]]-x[[2,n]]}
>             .
>             .
>             .
>       {x[[m,1]]-x[[m-1,1]],x[[m,2]]-x[[m-1,2]],...,x[[m,n]]-x[[m-1,n]]}
>
> ----------------------------------------------------------------------- 
> -------------------------------
>
> I built this code but it does not work
>
> r=Array[0,{m,n}]
> For[j=1,j=n,j++
>        r[[i,j]]=Table[a[[i+1,j]]-a[[i,j]],{i,1,m-1,1}]]
>
> thanks
>
> Paolo
>
>
One out of many ways:

mat = Array[a, {3, 3}]


{{a[1, 1], a[1, 2], a[1, 3]}, {a[2, 1], a[2, 2],
    a[2, 3]}, {a[3, 1], a[3, 2], a[3, 3]}}

Transpose[(Drop[RotateLeft[#] - #, -1] & ) /@
    Transpose[mat]]


{{a[2, 1] - a[1, 1], a[2, 2] - a[1, 2],
    a[2, 3] - a[1, 3]}, {a[3, 1] - a[2, 1],
    a[3, 2] - a[2, 2], a[3, 3] - a[2, 3]}}


Andrzej Kozlowski
Chiba, Japan
http://www.mimuw.edu.pl/~akoz/


  • Prev by Date: RE: matrix operations
  • Next by Date: Help Browser issue in 5.0.1 on Mac OS X
  • Previous by thread: matrix operations
  • Next by thread: matrix operations