MathGroup Archive 2007

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

Search the Archive

Re: About Table

  • To: mathgroup at smc.vnet.net
  • Subject: [mg75005] Re: About Table
  • From: "dimitris" <dimmechan at yahoo.com>
  • Date: Fri, 13 Apr 2007 02:19:54 -0400 (EDT)
  • References: <evksst$rid$1@smc.vnet.net>

I will try not sound elitistic.

But I can recall more than two (at least!) recent threads about
TableForm
that started from relevant queries of you! And as far as I remember
(and I have
good memory I think!) there were many replies to you, suggesting
various methods
of handling, by the well known gurus of this forum (no I don't
consider myself a guru!).

Didn't these replies cover your needs?

Anyway...

One way of working is

First creating the columns of your table (the third one is your data)

So

In[55]:=
lst1 = Table[Which[j <= 5, 0, j <= 10, 0.5, j <= 15, 1], {j, 1, 15}]

Out[55]=
{0, 0, 0, 0, 0, 0.5, 0.5, 0.5, 0.5, 0.5, 1, 1, 1, 1, 1}

Where we have used the flowing control function Which

In[56]:=
Information@Which

>From In[56]:=
"Which[test1, value1, test2, value2, ... ] evaluates each of the testi
in turn, returning the value of the valuei corresponding to the first
one that yields True."
>From In[56]:=
Attributes[Which] = {HoldAll, Protected}

Next

In[57]:=
lst2 = Table[Range[0, 2, 0.5], {3}] /. x_ :> IntegerPart[x] /;x != 0.5
&& x != 1.5//Flatten

Out[57]=
{0, 0.5, 1, 1.5, 2, 0, 0.5, 1, 1.5, 2, 0, 0.5, 1, 1.5, 2}

In this way I got the second column as you requested. I.e. the
elements {0, 0.5, 1, 1.5 ,2}
(*three integeres and two reals*) are recycling.

Also

In[59]:=
Information@IntegerPart

>From In[59]:=
"IntegerPart[x] gives the integer part of x."
>From In[59]:=
Attributes[IntegerPart] = {Listable, NumericFunction, Protected}

In[60]:=
Information@Flatten

>From In[60]:=
"Flatten[list] flattens out nested lists. Flatten[list, n] flattens to
level n. Flatten[list, n, h] flattens subexpressions with head h."
>From In[60]:=
Attributes[Flatten] = {Protected}

And lastly

In[61]:=
lst3 = {3, 6, 9, 4.4, 6.7, 5, 3, 6.2, 3.7, 5.2, 6.3, 9, 10, 12, 13.2}

Out[61]=
{3,6,9,4.4,6.7,5,3,6.2,3.7,5.2,6.3,9,10,12,13.2}

Here is the desired matrix

In[63]:=
mat = MapThread[List, {lst1, lst2, lst3}]

Out[63]=
{{0, 0, 3}, {0, 0.5, 6}, {0, 1, 9}, {0, 1.5, 4.4}, {0, 2, 6.7}, {0.5,
0, 5}, {0.5, 0.5, 3}, {0.5, 1, 6.2}, {0.5, 1.5, 3.7},
  {0.5, 2, 5.2}, {1, 0, 6.3}, {1, 0.5, 9}, {1, 1, 10}, {1, 1.5, 12},
{1, 2, 13.2}}

where

In[62]:=
Information@MapThread

>From In[62]:=
"MapThread[f, {{a1, a2, ... }, {b1, b2, ... }, ... }] gives {f[a1,
b1, ... ], f[a2, b2, ... ], ... }. MapThread[f, {expr1, \
expr2, ... }, n] applies f to the parts of the expri at level n."
>From In[62]:=
Attributes[MapThread] = {Protected}

And in table form as requested

In[64]:=
mat // TableForm[#1, TableAlignments -> Center, TableSpacing -> {3,
3}] &

\!\(\*
  TagBox[GridBox[{
        {"0", "0", "3"},
        {"0", "0.5`", "6"},
        {"0", "1", "9"},
        {"0", "1.5`", "4.4`"},
        {"0", "2", "6.7`"},
        {"0.5`", "0", "5"},
        {"0.5`", "0.5`", "3"},
        {"0.5`", "1", "6.2`"},
        {"0.5`", "1.5`", "3.7`"},
        {"0.5`", "2", "5.2`"},
        {"1", "0", "6.3`"},
        {"1", "0.5`", "9"},
        {"1", "1", "10"},
        {"1", "1.5`", "12"},
        {"1", "2", "13.2`"}
        },
      RowSpacings->3,
      ColumnSpacings->3,
      RowAlignments->Baseline,
      ColumnAlignments->{Center}],
    Function[ BoxForm`e$,
      TableForm[ BoxForm`e$,
        TableAlignments -> Center, TableSpacing -> {3, 3}]]]\)


Dimitris

=CF/=C7 Evanescence =DD=E3=F1=E1=F8=E5:
> Hello dear all:
> My questions are as follows:
> First I have a list is{3,6,9,4.4,6.7,5,3,6.2,3.7,5.2,6.3,9,10,12,13.2}
> Then I want to have tableform is as follows:
>
>     0      0       3
>     0     0.5     6
>     0       1      9
>     0     1.5    4.4
>     0       2     6.7
>    0.5     0       5
>    0.5    0.5     3
>    0.5      1     6.2
>    0.5    1.5    3.7
>    0.5      2     5.2
>     1        0     6.3
>     1       0.5     9
>     1         1     10
>     1       1.5    12
>     1          2    13.2
>
> Please tell me how can I do it.
> Thank you very much
> Evanescence 2007 04 11



  • Prev by Date: Re: bug in Integrate (5.2) (Fullani's integral)
  • Next by Date: Re: Variable containing code
  • Previous by thread: Re: About Table
  • Next by thread: Question about Part