Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
1998
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 1998

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

Search the Archive

Re: Piecewise defined functions

  • To: mathgroup at smc.vnet.net
  • Subject: [mg12988] Re: Piecewise defined functions
  • From: Tobias Oed <tobias at physics.odu.edu>
  • Date: Sun, 28 Jun 1998 02:52:11 -0400
  • Organization: Old Dominion University
  • References: <6mqep0$3gn@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Edward Neuman wrote:

> I'm working with the piecewise defined functions with a large number of
> subintervals. They can be defined using the UnitStep function.
> Manipulations
> (e.g., plotting, integration, etc.) with a function having a large
> number of  the UnitStep factors is often a time consuming job. Is it
> possible to force Mathematica to create a sequence of rules like this:
>
> g[x_/;x1 <= x <x2] := Expr1
> g[x_/;x2 <= x <x3] := Expr2
>              ....
>
> where the lists {x1, x2, ... } and {Expr1, Expr2, ... } are supplied by
> a user? Any help would be greatly appreciated.
>
> Regards,
> Edward Neuman

This works

In[1]:= x={x0,x1,x2,x3,x4}

Out[1]= {x0, x1, x2, x3, x4}

In[2]:= e={e1,e2,e3,e4}

Out[2]= {e1, e2, e3, e4}

In[3]:= xx=Thread[{Drop[x,-1],Rest[x],e}]

Out[3]= {{x0, x1, e1}, {x1, x2, e2}, {x2, x3, e3}, {x3, x4, e4}}

In[4]:= Scan[((g[x_ /; (#1<=x<=#2)]:=#3)&[Apply[Sequence,#]])&,xx]

In[5]:= ??g
Global`g

g[x_ /; x0 <= x <= x1] := e1

g[x_ /; x1 <= x <= x2] := e2

g[x_ /; x2 <= x <= x3] := e3

g[x_ /; x3 <= x <= x4] := e4

Tobias



  • Prev by Date: Re: Trigonometric equation????
  • Next by Date: Re: How to Extract a common factor from a Sum
  • Previous by thread: Piecewise defined functions
  • Next by thread: Inconsistencies in pattern matching.