Define new functions the same way you would using pen and paper.
Functions can be defined in terms of library functions:
You may define functions of several variables. The arguments can be scalars, boolean, arrays, matrices or other functions. The type used by the function is resolved at run time.
For example, function
h(p) below finds the maximum entry and returns it squared:
h(p) above can be used with arrays or matrices:
h(p) still works if the argument is a scalar:
Once a user function has been created, you may use it in the definition of another function:
User functions may return any type of value (boolean, array, matrix, etc.)
Example of a boolean being returned:
In this example, a unit vector is returned:
User-defined functions are of two types. If the function you create uses curly brackets it is considered a program. Programs have different rules; for more information on user-defined programs see section Programming.
Simple user-defined functions are usually created in one line. The next example shows a fundamental property of variable scope:
The example above shows that simple functions look for variables in the global scope. Notice
m is searched in the global scope at runtime.
If the value of
m changes, function
f changes automatically as shown
User-defined functions are differentiable if the function definition does not make
use of curly brackets and it is differentiable in the sense of standard Calculus. To test
whether a function is differentiable (in the Calcugator sense) use function
Differentiable functions can be processed using the symbolic toolkit. See the Symbolic Toolkit for more information.