Piecewise once more

• To: mathgroup at smc.vnet.net
• Subject: [mg109219] Piecewise once more
• From: Peter Breitfeld <phbrf at t-online.de>
• Date: Sat, 17 Apr 2010 06:05:41 -0400 (EDT)

```When trying to find an answer to mercia's post I came into this

stepFunction::usage =
"stepFunktion[x,{x1,x2,...,xn},valfunc] generates a \
stepfunction using Piecewise from List xi, where x1<x_2<...xn
valfunc is a function of two parameters to calculate the value \
inside Interval [\!\(\*SubscriptBox[\"x\", \
\"i\"]\),\!\(\*SubscriptBox[\"x\",
RowBox[{\"i\", \"+\", \"1\"}]]\)]." ;

stepFunction[x_, mesh_List, valfunc_] :=
Module[{args, bed, werte, part},
part = Partition[mesh, 2, 1];
werte = valfunc @@@ part;
bed = (#1 <= x < #2) & @@@ part;
args = Transpose[{werte, Flatten[bed]}];
Evaluate[Piecewise[Evaluate@args]]]

treppe[y_]=stepFunction[y, mesh,(#1+#2)/2&]

I get the warning:
Piecewise::pairs: The first argument of args\$706 of Piecewise is not a
list of pairs.

But the output is ok and test like

treppe /@Range[1,20]

show the right result. A Plot works fine

What's wrong in my code to produce the message?

\$Version= 7.0 for Mac OS X x86 (64-bit) (February 19, 2009)

--
_________________________________________________________________
Peter Breitfeld, Bad Saulgau, Germany -- http://www.pBreitfeld.de

```

• Prev by Date: Generalization of Variables ?
• Next by Date: Re: make arrows same size in VectorPlot?
• Previous by thread: Re: Generalization of Variables ?
• Next by thread: Question on replacementFunction