Re: Step functions
- To: mathgroup at smc.vnet.net
- Subject: [mg17083] Re: [mg17097] Step functions
- From: "Tomas Garza" <tgarza at mail.internet.com.mx>
- Date: Fri, 23 Apr 1999 02:32:16 -0400
- Sender: owner-wri-mathgroup at wolfram.com
Alessio Massaro [alessio.massaro at cern.ch] wrote:
> Can anyone help me to build a step function out of a series of
> {x,y} pairs?
>
> For ex.., consider an ordered random {x,y} series like
>
> data=Sort[Table[{Random[],Random[]}, {10}], First[#1]<First[#2]&]
>
> I would like to build a function f[ { {x1, y1}, {x2, y2}, ...}, x ], that
> evaluates to:
> - y[i] if x=x[i]
> - y[i+1] if x[i]<x<x[i+1]
> Here each point {xi, yi} determines f over the left-open interval
> x[i]<x<=x[i+1] of x.
> The right-open interval version would be:
> - y[i] if x=x[i]
> - y[i] if x[i]<x<x[i+1]
Hi, Alessio!
Of course, you could try to build the lines using graphics primitives, but
this is tedious. There goes an idea (due, I think, to J. Tischer). If the
domain where you want to display your step function is, e.g., {0, a}, try
this:
In[1]:=
redata=Transpose[{Append[Transpose[data][[1]],a],
Prepend[Transpose[data][[2]],0]}];
In[2]:=
foo=Interpolation[redata,InterpolationOrder->0];
In[3]:=
Plot[foo[x],{x,0,a}]
This will do the trick.
Good luck,
Tomas Garza
Mexico City