MathGroup Archive 2010

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

Search the Archive

piecewise function


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


  • Prev by Date: Re: Selecting subscripted variables from an expression
  • Next by Date: Re: Equation problem
  • Previous by thread: Re: NIntegrate Confusion
  • Next by thread: Re: piecewise function