MathGroup Archive 1995

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

Search the Archive

RE: trying to evaluate a piecewise function

  • Subject: [mg2156] RE: [mg2114] trying to evaluate a piecewise function
  • From: jfultz ("John R. Fultz")
  • Date: Tue, 10 Oct 1995 06:37:33 GMT
  • Approved:
  • Distribution: local
  • Newsgroups: wri.mathgroup
  • Organization: Wolfram Research, Inc.
  • Sender: daemon at ( )

If you have variables exprs and subdomains defined like so:

exprs={x, x^2, 2x};

then, you could do:


which returns:

{0 <= x < 1, x, 1 <= x < 2, x , 2 <= x <= 5, 2 x}

Note that this is the exact format required as the arguments to
Which.  So, you can use the Apply command (or its shorthand
equivalent, @@) to apply Which to the list and create a function
which can easily be plotted.

Plot[Which @@ whichlist, {x, 0, 5}]

Hope this helps!


John Fultz
Technical Support

From: 	Alberto.MERONI[SMTP:Alberto.Meroni at]
Sent: 	Wednesday, October 04, 1995 12:53 AM
To: 	mathgroup at
Subject: 	[mg2114] trying to evaluate a piecewise function

I am trying to solve this problem:
I have a list of expressions {expr1,expr2,...exprN} each
valid in a subdomain specified as a list {l1<x<=u1,l2<x<=u2..
,lN<x<=uN} and I would like to have a function which evaluate a plot
this piecewise object.
1) Everything is continous
2) The union of all subdomains exhaust the domain l1<x<=uN
3) The number N is a given parameter (of order 10)
4) I would not like for each value of N to enter something like
If [clause1,expr1,....]
Somebody has a way to do this ?
I could not find a solution in the Book.
For information this thing comes from the following problem:
You are given a list of points and you want to find a  piecewise
continous  approximation to  these values. It is related to the so
called multicanonical technique of Monte Carlo simulation.
Thank you very much
		Alberto Meroni
		ameroni at

  • Prev by Date: Re: MMA for OS2/Windows front end, Help
  • Next by Date: MMA movie with sound to QT
  • Previous by thread: trying to evaluate a piecewise function
  • Next by thread: RE: trying to evaluate a piecewise function