plotting piecewise functions



Here's what I really need:

(C2) f(x):=if x<0 then 0 else if x<1 then x else 1$
(C3) plot2d(1-f(x)^3,[x,-1,2]);
MACSYMA was unable to evaluate the predicate:
x < 0
#0: f(x=x)
  -- an error.  Quitting.  To debug this try DEBUGMODE(TRUE);)

Ah! I've just thought of possible solution...
(C4) plot2d('(1-f(x)^3),[x,-1,2]);
... it works, but this looks strange, since plot2d(1-sin(x)^3,[x,-1,2]) 
works 'as is'... Can this get unified somehow?
--
Andrei Zorine

Stavros Macrakis wrote:
> A piecewise definition is fine, but the function must be well-defined
> within the whole domain.
> 
> For example:
> 
>   plot2d( '(if x>1 then 3 else 1) ,
>           [x,0,3] );  /* Expression form */
> 
>     Note that you must quote the expression.
> 
> Logically, you should also be able to write:
> 
>   plot2d( lambda([x], if x>1 then 3 else 1) ,
>           [x,0,3] );                         /* Functional form */
> 
> but Maxima has a bug, and doesn't recognize the lambda expression as a
> function.  
> 
> You can also define a separate function:
> 
>   f(x):= if x>1 then 3 else 1;
>   plot2d( f(x) , [x,0,3] );    /* Expression form */
>   plot2d( f    , [x,0,3] );    /* Functional form */
>     Though the x is otiose, it is required.
> 
> For greater efficiency, you can do translate(f) or compile(f) before
> plotting, though this sometimes introduces other problems (translation
> bugs).
> 
> Unfortunately, there is currently no way to specify that a function is
> undefined in some subdomain, or that it is infinite, so you must use
> bogus values:
> 
>   plot2d( '( if abs(x)<1.0e-1 then 0 else 1/x) , [x,-2,2] )
>   plot2d( 
>     Note bogus assumption of continuity in the plot.
> 
> I would hope that in a future version of plot2d, it would understand
> return values of UND, INF, etc.
> 
> You can get around this by setting the y-range explicitly, and using
> points outside the plot area.  This only really works correctly when the
> function crosses the y-max/min:
> 
>   plot2d( '(if abs(x)<1.0e-1 then signum(x)*1.0e3 else 1/x) ,
>           [x,-2,2] ,
>           [y,-10,10] )
> 
> 
> 
>