next up previous contents
Next: Glossary Up: Expressions Previous: Ternary   Contents


User-defined

New user-defined variables and functions of one through five variables may be declared and used anywhere, including on the plot command itself.

User-defined function syntax:

     <func-name>( <dummy1> {,<dummy2>} ... {,<dummy5>} ) = <expression>

where 5#5expression6#6 is defined in terms of 5#5dummy16#6 through 5#5dummy56#6.

User-defined variable syntax:

     <variable-name> = <constant-expression>

Examples:

     w = 2
     q = floor(tan(pi/2 - 0.1))
     f(x) = sin(w*x)
     sinc(x) = sin(pi*x)/(pi*x)
     delta(t) = (t == 0)
     ramp(t) = (t > 0) ? t : 0
     min(a,b) = (a < b) ? a : b
     comb(n,k) = n!/(k!*(n-k)!)
     len3d(x,y,z) = sqrt(x*x+y*y+z*z)
     plot f(x) = sin(x*a), a = 0.2, f(x), a = 0.4, f(x)

Note that the variable pi is already defined. But it is in no way magic; you may redefine it to be whatever you like.

Valid names are the same as in most programming languages: they must begin with a letter, but subsequent characters may be letters, digits, "$", or "_". Note, however, that the fit mechanism uses several variables with names that begin "FIT_". It is safest to avoid using such names. "FIT_LIMIT", however, is one that you may wish to redefine. See the documentation on fit (p. [*]) for details.

See show functions (p. [*]), show variables (p. [*]), and fit (p. [*]).



Rick Perry 2006-02-15