       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:= x={x0,x1,x2,x3,x4}

Out= {x0, x1, x2, x3, x4}

In:= e={e1,e2,e3,e4}

Out= {e1, e2, e3, e4}

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

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

In:= ??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.