If a graph depends on a user-defined function, you may want to define the function when the parameter is a formal variable. For this, it can be useful to test the type of the parameter while the function is being defined. (See Chapter Section 25 for information about programming in Xcas.)
For example, suppose that f and g are defined by:
f(x):={ if (type(x)!=DOM_FLOAT) return 'f'(x); while (x>0) { x--; } return x; } |
and
g(x):={ while (x>0) { x--; } return x; }:; |
Graphing these (see Section 19.2.1):
F:=plotfunc(f(x)); G:=plotfunc(g(x)) |
they will both produce the same graph. However, the graphic G won’t be reusable. Entering:
F |
reproduces the graph, but entering:
G |
produces the error:
|
Internally, F and G contain the formal expressions f(x) and g(x), respectively. When Xcas tries to evaluate F and G, x has no value and so the test x>0 produces an error in g(x), but the problem is avoided in the second line of f(x).