Define numeric variables with functions
Updated 30 Aug 2024
You can use any of the following functions when defining the minimum and maximum fields for a numeric variable or in an answer box.
Function | Format | Purpose & Example |
---|---|---|
rand | rand(range-start,range-end,exponent) | Purpose: Generates a random number within a specified range, optionally rounded to a specific power of 10. Example: |
round | round(value,exponent) | Purpose: Rounds a value to a specific power of 10. Example: |
sigdig | sigdig(value,exponent) | Purpose:
Rounds a value to a specific number of significant digits.
Example: |
ifthenelse | ifthenelse(test,true_value,false_value) | Purpose:
Returns one of two values depending on the result of a logical test. Example: |
The ifthenelse function returns one of two values, depending on the result of a logical test. In the example below, the ifthenelse function produces a value 0 or 1 for y, based on the value of the variable x.
- If x is a number between 1 and 5, a value of 0 is returned for y.
- If x is a number between 6 and 10, a value of 1 is returned for y.
Define numeric variable x
Define numeric variable y with ifthenelse
Choose Formula or single numeric value and enter ifthenelse(x>5,1,0) in the box as a formula.
Note: Alternatively, you could define the variable by choosing Value and entering ifthenelse(x>5,1,0) for both the minimum and maximum, with a Step value of 0. Either way, this value will display as a formula in the Define Variable form if you open the variable later for edit.
Your defined variables list would look like this. The variable "y" appears as a min, max, step value, regardless of whether you entered it as a formula or as min, max, step.
The variables e1, e2, and e3 defined below are in an item to calculate the total energy required to convert a solid to a gas using heat capacity, heat of fusion, and heat of vaporization.
Variable | Description |
---|---|
e1 |
Function n_1*6.02 is rounded to 10-1, or to the first decimal place. For example:
|
e2 |
Function (m_1*4.184)/10 is rounded to 10-1, or to the first decimal place. |
e3 |
Function n_1*40.7 is rounded to 100, or to the first integer. For example:
|
See also: