[Date Index]
[Thread Index]
[Author Index]
Re: FW: matrix operations
*To*: mathgroup at smc.vnet.net
*Subject*: [mg46523] Re: FW: matrix operations
*From*: Erich Neuwirth <erich.neuwirth at univie.ac.at>
*Date*: Sun, 22 Feb 2004 11:27:22 -0500 (EST)
*References*: <c0s7cd$sbi$1@smc.vnet.net>
*Sender*: owner-wri-mathgroup at wolfram.com
Map[(#[[2]] - #[[1]]) &, Partition[mat, 2, 1]]
is another way of doing it functionally.
Quite often Map is easier to understand than Apply with a level
specification.
E. Martin-Serrano (Houston) wrote:
> Hi,
>
> I have put this David's response in a notebook called "The wonders of
> functional programming (by David Park).nb", mainly, because of the use he
> does of "%". Notice the "spaces" and "parenthesis" in the file's name, and
> its length as a string.
>
> Spaces and length in Mathematica file names is something that has always
> worried me:
>
> My question is: while this file name is instructive, for the purpose of
> maintaining a library and documentation. Which are the implications from the
> side of the capability of Mathematica in handling package names, and such
> strings of characters as symbols?
>
> E. Martin-Serrano
>
>
>
>
>
> -----Original Message-----
> From: David Park [mailto:djmp at earthlink.net]
To: mathgroup at smc.vnet.net
> Subject: [mg46523] matrix operations
>
>
> Paolo,
>
> The wonders of functional programming! Here's an example.
>
> mat = Array[x, {4, 4}]
>
> Partition[mat, 2, 1]
> (answer = #2 - #1 & @@@ %) // MatrixForm
>
> @@@ is the Apply function, mapped onto the first level of mat. #2 - #1& is a
> pure function that subtracts the second argument from the first argument.
>
> David Park
> djmp at earthlink.net
> http://home.earthlink.net/~djmp/
>
>
> -----Original Message-----
> From: paolo tarpanelli [mailto:tarpanelli at libero.it]
To: mathgroup at smc.vnet.net
> Subject: [mg46523] matrix operations
>
>
> 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
>
> ----------------
>
>
Prev by Date:
**Re: Bernoulli variable algebra**
Next by Date:
**Re: Computing sets of equivalences**
Previous by thread:
**Re: matrix operations**
Next by thread:
**How to numerically estimate an asymptotic equivalent?**
| |