Mathematica 9 is now available
Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2010

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

Search the Archive

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


  • 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