fb_unit - mkraska/meclib GitHub Wiki
Feedback function for units input.
This function performs the following checks with units (see fb_vars and fb_number for other functions):
- Do the units match? This is redundant to the UnitsRelative answer test.
- Is the value off by exactly an integer power of 10? This indicates correct mantissa and problems with unit conversion. Mantissa Check
- Is the sign correct? Check of Sign
- If
tol
is 0 or the deviation is less thantol
: display % deviation with one decimal place. - If teacher's answer is zero and student's answer is not: Absolute value of the response is too big.
- If student's answer is zero and teacher's answer is not: Absolute value of the response is too small.
- Otherwise display % deviation with one significant digit (e.g. at least 0.01% or 0.3% or 30% deviation)
You can try the function interactively in our Demo Moodle Course (see quiz fb_unit() interactive tryout).
fb_unit(sans, tans, tol)
Returns the text to be displayed for feedback.
fb_unitOK(sans, tans, tol)
Returns the test result (true or false).
sans
student's answer,tans
teacher's answer,tol
relative tolerance for the mantissa. Set it to zero to avoid the tests and just display the deviation.
Question variables
German version:
stack_include("https://raw.githubusercontent.com/mkraska/meclib/main/Maxima/fb_value.mac");
English version:
stack_include("https://raw.githubusercontent.com/mkraska/meclib/main/Maxima/fb_value_EN.mac");
Question Text
The question text must contain a [lang ](/mkraska/meclib/wiki/lang-)
block to activate localization in the feedback functions.
[lang code="de"](/mkraska/meclib/wiki/lang-code="de") [/lang](/mkraska/meclib/wiki//lang)
[lang code="other"](/mkraska/meclib/wiki/lang-code="other") [/lang](/mkraska/meclib/wiki//lang)
PRT
- Set
simp
tofalse
. This enables input like0*kg
to keep the unit factor for feedback. - Use a UnitRelative answer test with suppressed feedback (unit mismatch is handled by the feedback function).
Put this to the feedback text of the false
branch of the first node.
{@fb_unit(sans, tans, tol)@}
In the true
branch of the first node, use this to suppress the tests and just display the deviation:
{@fb_unit(sans, tans, 0)@}
You could pre-calculate the value in the feedback variables, but that doesn not reliably avoid empty checks (with no feedback)