Repository navigation
fb_coeffs()
fb_coeffs() is meant for symbolic student answers that are linear in a set of variables but whose coefficients are floating-point numbers, e.g. an equilibrium condition built from forces at arbitrary angles, 0.866*F_A - 0.5*F_B + 12.3. In such cases fb_vars()'s symbolic term check and the AlgEquiv answer test are too strict, because the coefficients only agree within a tolerance.
The function works in two steps:
- It checks the set of variables with fb_vars (missing or unexpected variables). If this check fails, its feedback is returned and step 2 is skipped.
- It compares the coefficient of each variable of
tanswith the corresponding coefficient insansnumerically, using fb_unit. For each coefficient outside the tolerance, a message is appended that names the variable together with the deviation feedback offb_unit(), e.g. "Coefficient of b: The value is too large by at least 60%."
If all coefficients match, the feedback reads "The equation is correct." (German: "Die Gleichung stimmt.").
[text, ok]: fb_coeffs(sans, tans, tol, description)
-
sansstudent's answer -
tansteacher's answer -
toltolerance, must be positive. It is used in two ways:- as the relative tolerance for each coefficient comparison (passed on to
fb_unit()), e.g.0.01for 1 % - as an absolute threshold below which a coefficient counts as zero, i.e. the variable is treated as not present at all (protects against floating-point noise such as
1e-13*b, same as thetolparameter of fb_vars)
- as the relative tolerance for each coefficient comparison (passed on to
-
descriptiontext placed in front of the feedback, e.g."\\(\\sum F_x\\):". Use""if no description is wanted.
Returns a list [text, ok]:
-
textthe feedback text. It always starts withdescription, also when everything is correct. -
oktrueif the variable set and all coefficients match, otherwisefalse
Like fb_vars() and fb_unit(), fb_coeffs() does not insert line breaks. Every message starts with a non-breaking space ( ), so the feedback can be placed directly behind the input and its validation. description is inserted verbatim. Do not end it with a space: "AB:" gives "AB: The equation is correct.", whereas "AB: " shows a double gap.
- A constant term (a part of the expression that does not multiply any variable) is not checked.
2.0*a + 3.0*b + 5is accepted for2.0*a + 3.0*b. - Only the linear coefficient of each variable is compared. A variable that appears only nonlinearly (e.g.
a^2,sin(alpha)) is not checked; pass such a sub-expression as a separate variable or use a different check. -
tol = 0is not supported:fb_unit()then reports the deviation for every coefficient, so the result is alwaysfalse. - Angles given in degrees with the symbol
degmust be converted withdeg2rad()(also defined infb_value.mac) before comparison, e.g.fb_coeffs(deg2rad(S_GG1), GG1, 0.05, ""). - The function never activates STACK's units feature on its own (see fb_unit).
stack_include("https://raw.githubusercontent.com/mkraska/meclib/main/Maxima/fb_value.mac");
The question text must contain a [[lang ]] block to activate localization in the feedback functions.
[[lang code="de"]] [[/lang]]
[[lang code="other"]] [[/lang]]
[textGG1, okGG1]: fb_coeffs(S_GG1, GG1, 0.01, "");
- Answer test:
AlgEquiv - SAns:
okGG1 - TAns:
true
{@textGG1@}
demo_questions/contact_demo_01.xml uses fb_coeffs() for two equilibrium conditions entered by the student, with angles in degrees:
[textGG1, okGG1]: fb_coeffs(deg2rad(S_GG1), GG1, 0.05, "");
- fb_vars check of the variable set (used internally in step 1)
- fb_unit numeric comparison (used internally in step 2)
-
Feedback for "dir" equilibrium in a chosen direction,
tolon the same footing
For tryout use the Meclib Workbench. It requires a local clone of this repository and a local Maxima installation. The workbench includes a rich editor for STACK questions with fast preview including CAStext and Mathjax rendering.
For older versions of Meclib you can use jsfiddle for tryout.
In order to try code snippets in jsfiddle,
- copy the code from the wiki page to the clipboard
- follow the link for the JSXGraph version you want to try
- Replace the code in the HTML section (contents of
<p id="init">) with the content of the clipboard
The remaining jsfiddle pages don't seem to work any more (as of 04/26)