MathGroup Archive 1995

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

Search the Archive

RE: trying to evaluate a piecewise function

  • To: mathgroup at smc.vnet.net
  • Subject: [mg2156] RE: [mg2114] trying to evaluate a piecewise function
  • From: "John R. Fultz" <jfultz>
  • Date: Tue, 10 Oct 1995 02:37:33 -0400

If you have variables exprs and subdomains defined like so:

exprs={x, x^2, 2x};
subdomains={0<=x<1,1<=x<2,2<=x<=5};

then, you could do:

whichlist=Flatten[Transpose[{subdomains,exprs}]]

which returns:

                             2
{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!

Sincerely,

John Fultz
Technical Support

----------
From: 	Alberto.MERONI[SMTP:Alberto.Meroni at th.u-psud.fr]
Sent: 	Wednesday, October 04, 1995 12:53 AM
To: 	mathgroup at smc.vnet.net
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 psisun.u-psud.fr





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