       Re: Piecewise function generator

• To: mathgroup at christensen.cybernetics.net
• Subject: [mg1154] Re: Piecewise function generator
• From: villegas (Robert Villegas)
• Date: Sat, 20 May 1995 00:53:19 -0400
• Organization: Wolfram Research, Inc.
• References: <3p8shv\$6b8@news0.cybernetics.net>

```REECE_D <REECE+_D%A1%Electromagnetic_Sciences at mcimail.com> writes:

>    I want to generate a piecewise continuous linear function by giving a
> function, call it F, a list of {x,y} values defining the corners of the
> function.  I can't seem to do it.  Does anyone out there have a quick way
> of doing it?
>
>    pts={{20,0.08},{50,0.8},{250,0.8},{5000,0.004}}
>
>    F[pts_] := ????
>
>    F[pts]
>
>    Out:
>    {(0.72 f-12)/30 /; 20<=f<=50,
>    ...}

A quick and easy way is Interpolation with InterpolationOrder->1

In:= pts={{20,0.08},{50,0.8},{250,0.8},{5000,0.004}}

Out= {{20, 0.08}, {50, 0.8}, {250, 0.8}, {5000, 0.004}}

In:= f[x_] = Interpolation[pts, InterpolationOrder->1][x]

Out= InterpolatingFunction[{20, 5000}, <>][x]

It's easier to see the effect for this data set:

In:= pts = Table[{i, Sin[i]}, {i, 7}]

Out= {{1, Sin}, {2, Sin}, {3, Sin}, {4, Sin}, {5, Sin},

>    {6, Sin}, {7, Sin}}

In:= g[x_] = Interpolation[pts, InterpolationOrder->1][x]

Out= InterpolatingFunction[{1, 7}, <>][x]

In:= Plot[g[x], {x, 1, 7}]

Out= -Graphics-

Robby Villegas

```

• Prev by Date: Pretty Graphics of Astroid by envolope
• Next by Date: Re: Finding Regression Coefficient
• Previous by thread: Piecewise function generator
• Next by thread: Re: Piecewise function generator