Meclib tutorial: Add more input fields and randomization - mkraska/meclib GitHub Wiki

Back to My first Meclib question

Add Randomization

We want to create random triangles.

Question variables

  • Replace the definitions of aa and bb with random numbers. In order to get reasonable triangles, randomly selected pairs of values are used.
[aa,bb]: rand([ [1,4], [1,3], [2,4], [2,3], [2,2], [3,3], [3,2], [3,1], [4,2], [4,1] ]); 

Question note

Randomized questions need a question note. It must be unique for each variant of the question but it may contain added information.

  • Add {@'a=aa@},{@'b=bb@} to the Question note field.

Preview

  • Press Save changes and continue editing
  • Press Preview

image

Add Input for Exact Length of c

The exact length of c is added as an algebraic input.

Question variables

  • Add this H: sqrt(aa^2+bb^2)*L; Hnum: float(sqrt(aa^2+bb^2)); below the random variable definition. This defines the reference solution for exact algebraic and approximate numeric input.

Question text

  • Add the following lines to the question text (at the end)
<p>What is the exact length of the hypotenuse \(c\) if the grid width is \(L\)?</p>
<p>[input:S_H](/mkraska/meclib/wiki/input:S_H) [validation:S_H](/mkraska/meclib/wiki/validation:S_H) [feedback:H](/mkraska/meclib/wiki/feedback:H)</p>
  • Press Verify the question text and update the form

Input S_H Make some adjustments:

  • Model answer: H
  • Insert stars: Insert stars for spaces only
  • Syntax hint: expression
  • Hint attribute: Placeholder
  • Show the validation: Yes, compact

Input S_Ha Make some adjustments (could have been done earlier):

  • Syntax hint: expression
  • Hint attribute: Placeholder

Potential response tree H

  • PRT feedback style: Compact
  • Node 1
    • Answer test: AlgEquiv (default)
    • SAns: S_H
    • TAns: H

Preview

  • Press Save changes and continue editing
  • Press Preview
  • Press Fill in correct responses
  • Press Check

image

Add Input for the Approximate Length of c

The approximate length of c is added as an numeric input.

Question text

  • Add the following lines to the question text (at the end)
<p>What is the numeric value of the length of the hypotenuse if the grid width is \(1\,\rm{cm}\)?</p>
<p>[input:S_Hnum](/mkraska/meclib/wiki/input:S_Hnum) [validation:S_Hnum](/mkraska/meclib/wiki/validation:S_Hnum) [feedback:Hnum](/mkraska/meclib/wiki/feedback:Hnum)</p>

  • Press Verify the question text and update the form

Input S_Hnum Make some adjustments:

  • Input type: Units
  • Model answer: Hnum*cm
  • Insert stars: Insert stars for spaces only
  • Syntax hint: number with unit
  • Hint attribute: Placeholder
  • Forbid floats: No
  • Show the validation: Yes, compact

Potential response tree Hnum

  • PRT feedback style: Compact
  • Node 1
    • Answer test: UnitsRelative
    • SAns: S_Hnum
    • TAns: Hnum*cm
    • Test options: 0.05

Preview

  • Press Save changes and continue editing
  • Press Preview
  • Press Fill in correct responses

image

The Units input type triggers STACK to inject units in the namespace of the complete question. This seem to interfere with the validation of the algebraic expression.

This is mitigated by adding the extra option nounits to the algebraic input field. This still doesn't avoid unit formatting (roman instead of italic) of symbols which coincide with unit names but avoids the validation error message.

Input S_Ha

  • Extra options: nounits

To be safe we do the same in the other algebraic input:

Input S_Ha

  • Extra options: nounits

Preview

  • Press Save changes and continue editing
  • Press Preview
  • Press Fill in correct responses
  • Press Check

image

Note that there is still a glitch: the symbol $L$ in the validiation isn't italic, because it is interpreted as the unit Liter.

Back to My first Meclib question