fb_coeffs() - mkraska/meclib GitHub Wiki

Numeric comparison of coefficients in linear expressions

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:

  1. 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.
  2. It compares the coefficient of each variable of tans with the corresponding coefficient in sans numerically, using fb_unit. For each coefficient outside the tolerance, a message is appended that names the variable together with the deviation feedback of fb_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)

  • sans student's answer
  • tans teacher's answer
  • tol tolerance, 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.01 for 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 the tol parameter of fb_vars)
  • description text placed in front of the feedback, e.g. "\\(\\sum F_x\\):". Use "" if no description is wanted.

Returns a list [text, ok]:

  • text the feedback text. It always starts with description, also when everything is correct.
  • ok true if the variable set and all coefficients match, otherwise false

Formatting

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.

Limitations

  • A constant term (a part of the expression that does not multiply any variable) is not checked. 2.0*a + 3.0*b + 5 is accepted for 2.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 = 0 is not supported: fb_unit() then reports the deviation for every coefficient, so the result is always false.
  • Angles given in degrees with the symbol deg must be converted with deg2rad() (also defined in fb_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).

Question variables

stack_include("https://raw.githubusercontent.com/mkraska/meclib/main/Maxima/fb_value.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)

Feedback variables (PRT)

[textGG1, okGG1]: fb_coeffs(S_GG1, GG1, 0.01, "");

PRT node

  • Answer test: AlgEquiv
  • SAns: okGG1
  • TAns: true

Feedback (true and false branch, or general PRT feedback)

{@textGG1@}

Example

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, "");

See also

  • 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, tol on the same footing