Calculated question type: Difference between revisions
Chad Burrus (talk | contribs) (added some information about how to construct a formula for a calculated question) |
Helen Foster (talk | contribs) (formatting, headings) |
||
Line 1: | Line 1: | ||
{{Questions}} | {{Questions}} | ||
Calculated questions offer a way to create individual numerical questions by the use of | Calculated questions offer a way to create individual numerical questions by the use of wild cards that are substituted with individual values when the quiz is taken. | ||
Calculated questions are calculated based on the formula entered when the question is created, and then the answers are computed on the server when the question is submitted. This means that the formula must be in a standard format (so the server can interpret it). | Calculated questions are calculated based on the formula entered when the question is created, and then the answers are computed on the server when the question is submitted. This means that the formula must be in a standard format (so the server can interpret it). | ||
As a general rule, write these formulas like you would in a calculator such as the TI-89 | ==Calculated question format== | ||
As a general rule, write these formulas like you would in a calculator such as the TI-89. | |||
E.g. <code>3 + 5 * sin (3 / x)</code> | |||
* It's usually better to have too many parentheses 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. | PLease note: | ||
* 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. | * 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 equation above for instance. Notice that the ''3 / x'' is wrapped in parentheses--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 that value accordingly. | * Any special mathematical function must have parentheses around its values. Take the sine function in the equation above for instance. Notice that the ''3 / x'' is wrapped in parentheses--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 that value accordingly. | ||
==Available functions== | |||
A table of functions available for you to use appears below. It is altered from [http://us3.php.net/manual/en/ref.math.php PHP: Mathematical Functions], where you can get more information. (Be careful, as the page may contain more information than you want!) | |||
{| width="97%" border="1px" | {| width="97%" border="1px" | ||
!Function | !Function | ||
Line 138: | Line 145: | ||
|Hyperbolic tangent -- in radians!!! Convert your degree measurement to radians before you take the tanh of it. | |Hyperbolic tangent -- in radians!!! Convert your degree measurement to radians before you take the tanh of it. | ||
|} | |} | ||
==Predefined constants== | |||
Some predefined constants are available for you to use. A table of these appears below, altered from [http://us3.php.net/manual/en/ref.math.php PHP: Mathematical Functions], where you can get more information. (Be careful, as the page may contain more information than you want!) | |||
{| width="97%" border="1px" | {| width="97%" border="1px" | ||
Line 197: | Line 207: | ||
|1/sqrt(2) | |1/sqrt(2) | ||
|} | |} | ||
==Additional predefined constants== | |||
Some other constants '''may''' be available, depending on how your instance of Moodle is set up. | |||
{| width="97%" border="1px" | {| width="97%" border="1px" | ||
!Constant | !Constant | ||
Line 220: | Line 232: | ||
|} | |} | ||
[[Category:Question]] | [[Category:Question]] | ||
Revision as of 09:22, 21 February 2007
Calculated questions offer a way to create individual numerical questions by the use of wild cards that are substituted with individual values when the quiz is taken.
Calculated questions are calculated based on the formula entered when the question is created, and then the answers are computed on the server when the question is submitted. This means that the formula must be in a standard format (so the server can interpret it).
Calculated question format
As a general rule, write these formulas like you would in a calculator such as the TI-89.
E.g. 3 + 5 * sin (3 / x)
PLease note:
- 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 equation above for instance. Notice that the 3 / x is wrapped in parentheses--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 that value accordingly.
Available functions
A table of functions available for you to use appears below. It is altered from PHP: Mathematical Functions, where you can get more information. (Be careful, as the page may contain more information than you want!)
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 |
base_convert | Convert a number between arbitrary bases. Example: to get the value of 50 (in base 10) in base 5, you'd write "base_convert(50, 10, 5)" |
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 |
dechex | Decimal to hexadecimal |
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 remainder (modulo) of the division of the arguments |
hexdec | Hexadecimal to decimal |
is_finite | Finds whether a value is a legal finite number |
is_infinite | Finds whether a value is infinite |
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 |
mt_rand | Generate a better random value |
octdec | Octal to decimal |
pi | Get value of pi |
pow | 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
Some predefined constants are available for you to use. A table of these appears below, altered from PHP: Mathematical Functions, where you can get more information. (Be careful, as the page may contain more information than you want!)
Constant | Value | Description |
---|---|---|
M_PI | 3.14159265358979323846 | Pi |
M_E | 2.7182818284590452354 | e |
M_LOG2E | 1.4426950408889634074 | log_2 e |
M_LOG10E | 0.43429448190325182765 | log_10 e |
M_LN2 | 0.69314718055994530942 | log_e 2 |
M_LN10 | 2.30258509299404568402 | log_e 10 |
M_PI_2 | 1.57079632679489661923 | pi/2 |
M_PI_4 | 0.78539816339744830962 | pi/4 |
M_1_PI | 0.31830988618379067154 | 1/pi |
M_2_PI | 0.63661977236758134308 | 2/pi |
M_2_SQRTPI | 1.12837916709551257390 | 2/sqrt(pi) |
M_SQRT2 | 1.41421356237309504880 | sqrt(2) |
M_SQRT1_2 | 0.70710678118654752440 | 1/sqrt(2) |
Additional predefined constants
Some other constants may be available, depending on how your instance of Moodle is set up.
Constant | Value | Description |
---|---|---|
M_SQRTPI | 1.77245385090551602729 | sqrt(pi) |
M_SQRT3 | 1.73205080756887729352 | sqrt(3) |
M_LNPI | 1.14472988584940017414 | log_e(pi) |
M_EULER | 0.57721566490153286061 | Euler constant |