next up previous contents
Next: Plotting Functions. Up: Getting Started With Previous: Defining Functions

Defining Compound Functions

To define a function defined by different expressions in different parts of its domain, Maple supplies what is known as an if ... then ...else control structure. The syntax for this structure is

if condition then
action if condition is true
else
action if condition is false
fi;

This structure can be all on one line or on several lines; it doesn't matter. We can use this structure to define the function

with the following command.

  > f:= x -> if x>=0 then x+3 else 3-x fi ;

For defining compound functions involving more than two expressions, Maple has a more complicated control structure, if ...then ...else if ... . For more information, see the section on Maple and Compound Functions.



William W. Farr
Mon Aug 28 09:31:56 EDT 1995