Note: You are currently viewing documentation for Moodle 3.9. Up-to-date documentation for the latest stable version of Moodle may be available here: Calculated question type.

Calculated question type: Difference between revisions

From MoodleDocs
m (→‎Available functions: Slight reformatting)
Line 10: Line 10:
The test will very rarely appear the same way twice.
The test will very rarely appear the same way twice.


==CAUTION: At least ONE wildcard in one of the answers==
==CAUTION: Put at least ONE wildcard in one of the answers==
The main purpose of the calculated question is to create multiple versions of a question with different numerical values.
The main purpose of the calculated question is to create multiple versions of a question with different numerical values.
   
   

Revision as of 11:16, 27 November 2007

Calculated questions offer a way to create individual numerical questions by the use of wildcards (i.e {x} , {y}) that are substituted with random values when the quiz is taken.

For example, if you want to create a large number of "Calculate the area of a rectangle" problems to drill your students, you could create a question with two wildcards (i.e. {base}, {height}) and put in the "Correct Answer Formula=" input field {base} * {height} ( * being the multiplication sign ).

Correct Answer Formula= {base}*{height}


When a student takes the test, Moodle will randomly select values for {base} and {height} and grade the response using the result of the Correct Answer Formula.

The test will very rarely appear the same way twice.

CAUTION: Put at least ONE wildcard in one of the answers

The main purpose of the calculated question is to create multiple versions of a question with different numerical values.

If you don't need a random element, use the Numerical question type instead.

A three-step process

To create (or modify) a calculated question you need to:

Set up the question

Name

Give the question a descriptive name.

Question text

All variables "wildcard" you want Moodle to replace with generated values must be placed in curly braces. For example if you wanted to sum numbers A and B the wild cards would be {A} and {B} or even {FirstNumber} and {SecondNumber}
Question text should contains at least one wildcard (otherwise you wouldn't be using this kind of question).
The user have all the necessary information to answer correctly

Correct answer formula

  • define at least one formula answer containing at least the wildcards that were put in the question text and all the other parameter related to precision or units.
  • set 100% at least to one of the answers

Choose the dataset properties

For each wild card(s) there is a the dataset containing the data that will be substituted to the wild card.
The dataset can be
  • private i.e. only used by this question
  • shared i.e shared with other questions from the same category
A dataset definition is mandatory for each of the wild cards used in the formulas.
If you put in the question text some text between brackets {zzz} that is a possible wild card ,
you will be able to choose if it is really a wild card or not.

Edit the datasets

If you define a large number of values (actual maximum number = 100),
you get a wider range of different questions.

Question set-up

  1. If you wish, add general feedback.
  2. Enter the formula for the answer. Be sure to use the same placeholders so Moodle can substitute the same values.
  3. Determine the tolerance for error that you will accept in the answer. The tolerance and tolerance type combine to give a range of acceptable scores.
  4. Select the number of significant figures you want in the correct answer.
  5. Add correct answer feedback.
  6. Enter the units for the answer (e.g. meters, kg, etc.). Moodle will look for the correct units. If you want to enter other acceptable units, such as metric versus imperial distances, enter them along with a conversion factor.
  7. Click Save changes.
  8. On the next screen, choose whether to create substitution values for each placeholder only for this question, or for other questions in the same category.
  9. Click Save changes.
  10. Create a dataset for the question or questions in the category. For each placeholder, generate a series of acceptable values. The more values you generate, the more a question can be used without repeating values. Note that you must click the Add (number) items button to actually incorporate the displayed numbers into your question. Once added, you'll see a list of possible value (dataset) at the bottom, and you can proceed.
  11. Click Back to quiz editing.

Correct answer formula

DO NOT PUT THE = sign in the fomula.

  • In the recent versions of the calculated question type, you could have more than one answer formula and applied a specific grading value to each of them as long as there is at least one 100% correct answer formula.
If more than one correct answer formula input field are displayed when editing, 
your site has the multiple answer feature. 


  • As a general rule, write these formulas like you would in a calculator e.g. 3 + 5 * sin (3/{x})
  • Each function's placeholders and other arguments should be in parentheses (brackets). For example, if you want students to calculate the sine of one angle and two times cosine of another, you would enter sin({a}) + cos({b}*2).
  • It's usually better to have too many parentheses (brackets) than too few. The server won't care, and the more specific you are about what you mean, the more likely it will like your complex formulas.
  • There is no implicit multiplication. To you, the human editor, "5(23)" or "5x" may seem perfectly obvious. To the server doing the math, it's crazy talk and won't be understood. Always use the "*" for multiplication.
  • Any special mathematical function must have parentheses around its values. Take the sine function in the first bullet point for instance. Notice that the 3 / x is wrapped in parentheses (brackets)--this is so the server can understand it properly. Without those parentheses, the server won't know if you mean "(sin 3) / x" or "sin (3 / x)" and will reject the entire formula accordingly.

Available functions

Calculated questions can use more than simple arithmetic operators. The following functions are allowed in versions 1.5 and newer.

Function Explanation
abs Absolute value
acos Arc cosine -- in radians!!! Convert your degree measurement to radians before you take the acos of it.
acosh Inverse hyperbolic cosine -- in radians!!! Convert your degree measurement to radians before you take the acosh of it.
asin Arc sine -- in radians!!! Convert your degree measurement to radians before you take the asin of it.
asinh Inverse hyperbolic sine -- in radians!!! Convert your degree measurement to radians before you take the asing of it.
atan2 Arc tangent of two variables -- pass in two values like (x, y), and you'll get the atah(y/x), adjusted to the proper quadrant.
atan Arc tangent -- in radians!!! Convert your degree measurement to radians before you take the atan of it.
atanh Inverse hyperbolic tangent
bindec Binary to decimal
ceil Round fractions up
cos Cosine -- in radians!!! Convert your degree measurement to radians before you take the cos of it.
cosh Hyperbolic cosine -- in radians!!! Convert your degree measurement to radians before you take the cosh of it.
decbin Decimal to binary
decoct Decimal to octal
deg2rad Converts the number in degrees to the radian equivalent
exp Calculates the exponent of e
expm1 Returns exp(number) - 1, computed in a way that is accurate even when the value of number is close to zero
floor Round fractions down
fmod Returns the floating-point modulus of two numbers - i.e. the remainder when the first is divided by the second.
is_finite Finds whether a value is a legal finite number
is_infinite Finds whether a value is infinite
is_nan Finds whether a value is not a number
log10 Base-10 logarithm
log1p Returns log(1 + number), computed in a way that is accurate even when the value of number is close to zero
log Natural logarithm (ln)
max Find highest value
min Find lowest value
octdec Octal to decimal
pi Get value of pi
pow (numberToRaise, NumberRaisedTo) Exponential expression
rad2deg Converts the radian number to the equivalent number in degrees
rand Generate a random integer
round Rounds a float
sin Sine -- in radians!!! Convert your degree measurement to radians before you take the sin of it.
sinh Hyperbolic sine -- in radians!!! Convert your degree measurement to radians before you take the sinh of it.
sqrt Square root
tan Tangent -- in radians!!! Convert your degree measurement to radians before you take the tan of it.
tanh Hyperbolic tangent -- in radians!!! Convert your degree measurement to radians before you take the tanh of it.

Predefined constants

Actually there is NO Predefined constant that is allowed other than pi() as a function without parameter.