Re: how to round value in matrixs
- To: mathgroup at smc.vnet.net
- Subject: [mg31886] Re: how to round value in matrixs
- From: "Allan Hayes" <hay at haystack.demon.co.uk>
- Date: Sun, 9 Dec 2001 06:07:10 -0500 (EST)
- References: <9usrvq$ckn$1@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
David, Just a small point: We don't need Map, since Round is Listable and N is pretty aggressive, for example N[HoldComplete[{{Pi}}]] HoldComplete[{{3.14159}}] Thus: round[n_][num_] := N[Round[10^n*num]/10^n] mat = Array[Random[] &, {2, 2}] {{0.374869,0.745659},{0.142273,0.397676}} roundedmat = round[3][mat] {{0.375,0.746},{0.142,0.398}} -- Allan --------------------- Allan Hayes Mathematica Training and Consulting Leicester UK www.haystack.demon.co.uk hay at haystack.demon.co.uk Voice: +44 (0)116 271 4198 Fax: +44 (0)870 164 0565 "David Park" <djmp at earthlink.net> wrote in message news:9usrvq$ckn$1 at smc.vnet.net... > Tomasz, > > Here is a function which will round an approximate number to n places. > > round[n_][num_] := N[Round[10^n*num]/10^n] > > Here is a randomly generated matrix. > > mat = Array[Random[] &, {2, 2}] > {{0.39248, 0.541335}, {0.236583, 0.330804}} > > This rounds the matrix elements to 3 places (by Mapping round[3] onto the > elements of mat at level 2). > > roundedmat = Map[round[3], mat, {2}] > {{0.392, 0.541}, {0.237, 0.331}} > > David Park > djmp at earthlink.net > http://home.earthlink.net/~djmp/ > > > From: Tomasz [mailto:tomaszmach at poczta.onet.pl] To: mathgroup at smc.vnet.net > > > > Hi > > I use Mathematica 4.0 and I would like to know how I can to round matrix > > values becouse I calculate in Mathematica matrix which include number with > > 13 digits after point but a would like to 3 digits after point > > how do this . > > thanks for all > > > > > > > >