MathGroup Archive 2004

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

Search the Archive

Re: matrix operations

  • To: mathgroup at smc.vnet.net
  • Subject: [mg46361] Re: matrix operations
  • From: "Peter Pein" <no at spam.no>
  • Date: Mon, 16 Feb 2004 09:00:07 -0500 (EST)
  • References: <c0mohe$65t$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

"paolo tarpanelli" <tarpanelli at libero.it> schrieb im Newsbeitrag
news:c0mohe$65t$1 at smc.vnet.net...
> 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
>
> ----------------

Hi Paolo,

In[1]:= n=3; m=5;
        a=Table[x[i,j],{i,1,m},{j,1,n}];

In[3]:= a[[Range[2,m]]] - a[[Range[m-1]]]
Out[3]=
{{-x[1, 1] + x[2, 1], -x[1, 2] + x[2, 2], -x[1, 3] + x[2, 3]},
 {-x[2, 1] + x[3, 1], -x[2, 2] + x[3, 2], -x[2, 3] + x[3, 3]},
 {-x[3, 1] + x[4, 1], -x[3, 2] + x[4, 2], -x[3, 3] + x[4, 3]},
 {-x[4, 1] + x[5, 1], -x[4, 2] + x[5, 2], -x[4, 3] + x[5, 3]}}


gives the desired result, as

 Table[a[[i+1,j]]-a[[i,j]],{i,1,m-1,1},{j,1,n}] does.

--
Peter Pein, Berlin
petsie at arcAND.de
replace && by || to write to me




  • Prev by Date: AW: matrix operations
  • Next by Date: Re: Maximize function question
  • Previous by thread: RE: matrix operations
  • Next by thread: Re: matrix operations