piecewise function

*To*: mathgroup at smc.vnet.net*Subject*: [mg109173] piecewise function*From*: mircea <mircea.darau at gmail.com>*Date*: Wed, 14 Apr 2010 23:14:30 -0400 (EDT)

I want a define a piecewise constant function on an interval [a,b]. What I did is: s[x_] := Module[{out}, out = 0; For[i = 1, i <= N, i++, If[mesh[[i]] <= x < mesh[[i + 1]], out = (mesh[[i]] + mesh[[i + 1]])/2; Break[]]]; out]; where: mesh={x_1,x_2,..,x_{N+1} }, a=x_1<x_2<..<x_{N+1}=b However PiecewiseExpand /@ s[x] gives me 0..... Can you please help me? Thanks, Mirela