FW: RE: matrix operations
- To: mathgroup at smc.vnet.net
- Subject: [mg46383] FW: [mg46343] RE: [mg46329] matrix operations
- From: "E. Martin-Serrano \(Houston\)" <eMartinSerrano at houston.rr.com>
- Date: Mon, 16 Feb 2004 23:42:16 -0500 (EST)
- Sender: owner-wri-mathgroup at wolfram.com
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: [mg46383] [mg46343] RE: [mg46329] 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: [mg46383] [mg46343] [mg46329] 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 ----------------