Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #5199 > unrolled thread

Manipulate for differences tables. Can I call as function?

Started by"Christopher O. Young" <cy56@comcast.net>
First post2011-09-25 07:49 +0000
Last post2011-09-26 08:13 +0000
Articles 2 — 2 participants

Back to article view | Back to comp.soft-sys.math.mathematica


Contents

  Manipulate for differences tables. Can I call as function? "Christopher O. Young" <cy56@comcast.net> - 2011-09-25 07:49 +0000
    Re: Manipulate for differences tables. Can I call as function? A Retey <awnl@gmx-topmail.de> - 2011-09-26 08:13 +0000

#5199 — Manipulate for differences tables. Can I call as function?

From"Christopher O. Young" <cy56@comcast.net>
Date2011-09-25 07:49 +0000
SubjectManipulate for differences tables. Can I call as function?
Message-ID<j5mmde$rqj$1@smc.vnet.net>
I'd like to be able to use this Manipulate expression, which works fine on
its own, as a function that I can pass a list of integers to. The following
isn't allowed. Any hints on how to go about doing this?

diffTablePlot[intList_] =
 Manipulate[
  Column[{
    Column[
     Table[
      Grid[
       {Differences[list, i]},
       ItemSize -> {w, h}
       ],
      {i, 0, n}
      ],
     Alignment -> alignment
     ], (* Column *)
    
    ListLinePlot[
     Table[
      Table[
       With[
        {offset = If[alignment == "Left", 0, j 0.5]},
        {startX + offset + (i - 1), Differences[list, j][[i]] }
        ],
       {i, 1, Length[Differences[list, j]]}
       ],
      {j, 0, n}
      ],
     
     PlotMarkers -> Graphics[{PointSize[Medium], Point[{0, 0}]}],
     PlotStyle -> Table[Hue[0.85 k/n], {k, 0, n}],
     PlotRange -> {{startX, startX + Length[list] - 1}, {Min[list],
        Max[list]}},
     GridLines -> {Range[startX, startX + Length[list]],
       Range[Min[list], Max[list]]},
     AspectRatio ->  (Max[list] - Min[list])/Length[list],
     Frame -> True,
     GridLinesStyle -> Directive[Gray, Dotted]
     ]      (* Column *)
    }],(* Column *)
  
  "Finite difference table for a list of numbers",
  {list, InputField},
  {alignment, {"Left", "Center"}},
  {{startX, 1, "Start x"}, -10, 10, 1},
  {{n, 4}, 1, Length[list] - 1, 1}, (*
  Number of rows of differences *)
  {{w, 3}, 0, 4},       (*
  width and height of each item *)
  {{h, 1}, 0, 4},
  
  With[{userList = intList},
   Initialization :> (list =
      If[userList != "", userList, Table[2^k, {k, -4, 4}] ])
   ]
  ] (* Manipulate *)

[toc] | [next] | [standalone]


#5224

FromA Retey <awnl@gmx-topmail.de>
Date2011-09-26 08:13 +0000
Message-ID<j5pc6g$8be$1@smc.vnet.net>
In reply to#5199
Am 25.09.2011 09:49, schrieb Christopher O. Young:
> I'd like to be able to use this Manipulate expression, which works fine on
> its own, as a function that I can pass a list of integers to. The following
> isn't allowed. Any hints on how to go about doing this?

Manipulate has Attribute HoldAll, so it does see an unevaluated With 
where it wants an options. Actually there is no reason to use the With 
at all, so this will work fine:

diffTablePlot[intList_] :=
  Manipulate[
   Column[{Column[
      Table[Grid[{Differences[list, i]}, ItemSize -> {w, h}], {i, 0,
        n}], Alignment -> alignment],(*Column*)
     ListLinePlot[
      Table[Table[
        With[{offset = If[alignment == "Left", 0, j 0.5]}, {startX +
           offset + (i - 1), Differences[list, j][[i]]}], {i, 1,
         Length[Differences[list, j]]}], {j, 0, n}],
      PlotMarkers -> Graphics[{PointSize[Medium], Point[{0, 0}]}],
      PlotStyle -> Table[Hue[0.85 k/n], {k, 0, n}],
      PlotRange -> {{startX, startX + Length[list] - 1}, {Min[list],
         Max[list]}},
      GridLines -> {Range[startX, startX + Length[list]],
        Range[Min[list], Max[list]]},
      AspectRatio -> (Max[list] - Min[list])/Length[list],
      Frame -> True,
      GridLinesStyle ->
       Directive[Gray, Dotted]]      (*Column*)}],(*Column*)
   "Finite difference table for a list of numbers", {list,
    InputField}, {alignment, {"Left", "Center"}}, {{startX, 1,
     "Start x"}, -10, 10, 1}, {{n, 4}, 1, Length[list] - 1,
    1},(*Number of rows of differences*){{w, 3}, 0,
    4},(*width and height of each item*){{h, 1}, 0, 4},
   Initialization :> (list =
      If[intList != "", intList, Table[2^k, {k, -4, 4}]])
   ]

Do you know about how to set default values in functions? This will 
allow you to call diffTablePlot with no arguments:

diffTablePlot[intList_:""]:=...

Also I think that using Null or None instead of "" as a marker for "no 
list given" might be more conventional coding style, if you have any 
intention to conform to conventions :-)

hth,

albert

[toc] | [prev] | [standalone]


Back to top | Article view | comp.soft-sys.math.mathematica


csiph-web