Functions

You can create your own functions to combine existing functions into a single function definition.

To create a function:

  1. Create or edit the question or preface to which you want to add a function.

  2. Choose Variable Definitions from the Tools menu.

  3. To create a new function, click Add Variable. To edit an existing function, click the Edit link for that variable.

  4. Select Function from the Type drop-down menu.

  5. Enter a name for your function in the Name field. Function names must contain parentheses and a list of arguments. For example, your function name might be hypotenuse(a,b).

    The function name must be unique for the current question. Function names may be up to 32 characters and should contain only letters, numbers, and the underscore character. Function names must begin with a letter. Built-in function and constant names are reserved and may not be used as function names.

  6. (Optional) Enter a description of your function in the Description field. For example, a description might be hypotenuse function.

  7. Enter your function expression in the Expression field. For example, an expression might be sqr((a^2)+(b^2)). Use the list of available functions to help you create your function expression.

  8. Click Test to calculate a value, which is returned in the Calculated value field, for your variable.

  9. Click OK to record your function.

  10. Use the function you created just like the built-in functions when you create a variable. For example, you might create a variable called the_hypotenuse with a definition of hypotenuse(leg1,leg2).