MathGroup Archive 1998

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

Search the Archive

Automatic generation of piecewise functions


  • To: mathgroup@smc.vnet.net
  • Subject: [mg11549] Automatic generation of piecewise functions
  • From: "William F. Campbell" <valentin@wam.umd.edu>
  • Date: Sat, 14 Mar 1998 13:56:03 -0500
  • Organization: UMD Dept. of Meteorology

  I am trying to generate a single function f[x], which has different
definitions depending on the values of x (i.e. a piecewise function). 
I proceeded as follows:

Clear[f];
sample=Table[f[x_]=a[i]*x+b[i]/;Evaluate[x>=i-1&&x<=i],{i,2}]

The output returned looked correct:
{b[1]+a[1] x/;x>=0&&x<=1,b[2]+a[2] x/;x>=1&&x<=2}

When I looked at the definition for f, it seemed correct as well: ?f

Global `f

f[x_]=b[1]+a[1] x/;x>=0&&x<=1

f[x_]=b[2]+a[2] x/;x>=1&&x<=2

But when I attempted to use the definition, f[0.5]

0.5 a[1]+b[1]/;0.5>=0&&0.5<=1

whose full form is
FullForm[f[0.5]]

Condition[Plus[Times[0.5,a[1]],b[1]],
  And[GreaterEqual[0.5,0],LessEqual[0.5,1]]]

Why doesn't the Condition evaluate?  How can I change the construct used
in sample above to obtain a working definition for a piecewise
function?  BTW, If I fail to put Evaluate[] around the condition in the
definition of sample above, the output is even further from what I
want, {b[1]+a[1] x/;x>=i-1&&x<=i,b[2]+a[2] x/;x>=i-1&&x<=i}. --
Bill Campbell                          Correlation is not cause.




  • Prev by Date: Re: MultipleListPlot with Log Linear Scale
  • Next by Date: Re: Solving Overdetermined Systems
  • Prev by thread: ReadBinary, Byte Order for Double ?
  • Next by thread: RE: Automatic generation of piecewise functions