In Maple, how do I plot a procedure containing an if statement?
Using Maple, consider the following example to plot a procedure with
an if statement:
When you try to plot f(x), Maple returns an error
message. The problem is due to Maple's order of evaluation. Suppose
you invoke the following command:
Maple first tries to calculate the value of f(x) before
substituting the numeric values in for x. In the
procedure, Maple cannot evaluate the if statement, as it
cannot compare the size of x to 0; thus, it
returns the error message.
A simple solution is to use single quotes to delay evaluation until a numerical value has been passed to x:
> plot('f(x)',x=0..2); 1 + AAA + AA AA + AA AA + A A 0.8 AAA AAA + A AA + AA AA + AA AA 0.6 AAA AAA + A AA + AA AA + AA AA + AA AA 0.4 AAA AAA + AA AA + AA AA + AA AA 0.2 AA AA + AA AA + AA AA +AA AAA **--+--+---+---+--+---+---+---+--+---+---+--+---+---+---+--+---+---+--+--** 0 0 0.5 1 1.5 2A more elegant solution is to plot the function f instead
of the formula f(x), for example:
For more about Maple, see Maple at IU.
For more about statistical and mathematical software, email the UITS Stat/Math Center, visit the center's web page, or phone 812-855-4724 (IUB) or 317-278-4740 (IUPUI). The center is located in Bloomington at 410 N. Park Avenue, and is open for consultation by appointment Monday-Friday 9am-5pm.
Last modified on March 18, 2011.







