how to define a piecewise function



Am 21 Nov 2005 um 5:16 hat Barton Willis geschrieben:

> 
> -----Glenn Ramsey wrote: -----
> 
> >Next problem. How do I plot the piecewise function?
> 
> (%i1) f(x) := if x < 1 then 1-x else x^2;
> (%o1) f(x):=if x<1 then 1-x else x^2
> (%i2) plot2d('(f(x)),[x,-2,2]);
> 
> At the discontinuity, this graph has a bogus
> vertical line segment. I don't know how to fix that.
> 
> Barton
> 

Hello,
the vertical line segment can be omitted in using parametric plots.

plot2d(
   [ [parametric,t,1-t,[t,-2,1],[nticks,100]],
     [parametric,t,t**2,[t,1,2],[nticks,100]] ],
   [x,-2,2]);

Maybe with some tellsimpafter tricks one can put the function expressions into the plot 
command.

Hope this helps.

Volker van Nek