39
7 AUTHORING NUMERICAL, FORMULA, CUSTOM RESPONSE QUESTIONS
45
To specify where to sample the formulas for determining whether the student’s answer is
correct, you need to put a sampling specification in the Sample Points field. The sampling
specifications take the following format:
1. A comma-separated list of the variables you wish to interpret,
2. followed by “@” (not in quotes),
3. followed by any number of the following two things, separated by semi-colons:
(a) a comma-separated list of as many numbers as there are variables, which specifies
one sampling point, OR
(b) a comma-separated list of as many numbers as there are variables, followed by a
colon, followed by another list of as many numbers as there are variables, followed
by a #, followed by an integer.
The first form specifies one point to sample. The second form specifies a range for each
variable, and the system will take as many random samples from that range as the number
after the #.
For 2x
2
+4, with one variable “x”, one could specify:
• “x@2”, which will sample the answers only at 2. (This is generally a bad idea, as the
student could get lucky and match at that point)
• “x@1:5#4” will takes 4 samples from somewhere between 1 and 5.
• “x@1:5#4;10” will takes 4 samples from somewhere between 1 and 5, and also sample
at 10.
For 2x
2
+3y
3
+z, which has three variables, one could specify:
• “x,y,z@4,5,3:10,12,8#4;0,0,0”, which take four samples from the box determined by
the points (4, 5, 3) and (10, 12, 8), and also sample the point (0, 0, 0).
7.10.2 Formula Notes
• The formula evaluator can not handle things of the form “x + - y”. If you have a
random variable that may be positive or negative (as in the example following this
section), you can try wrapping the references to that variable in parentheses. As
always, it is a good idea to try out several randomized versions of your problems to
make sure everything works correctly.
• Never use relative tolerance in Formula Response problems. Relative toler-
ance is poorly defined in Formula Response problems. Always use absolute tolerance.
39
7 AUTHORING NUMERICAL, FORMULA, CUSTOM RESPONSE QUESTIONS
46
7.10.3 Example Formula Response
Avery simple formula response problem:
• In the Script, place the following:
$slope = &random(-5.0,5.0,.5);
$yint = &random(-5.0,5.0,.5);
$answer = "$slope*x + ($yint)";
• In the Text Block, place the following: “For a line with slope $slope and y-intercept
$yint, what is y equal to?”
• In the Answer, place the following: $answer
• Set the Tolerance to .000001.
• Set the Sample Points to x@0;1;2;3 .
7.11 Authoring Math Response Problems
Math response problems use a cas system to evaluate the student response. Which computer
algebra system is to be used is specified in the cas argument of the mathresponse tag; both
Maxima and R are supported. Maxima and R are also powerful stand-alone programs that
can be installed on most operating systems. If you are interested in writing Maxima or
Rproblems, it is a good idea to install a copy on your operating system to access help,
learn syntax, and test your expected responses outside the LON-CAPA environment. See
http://maxima.sourceforge.net/ or http://www.r-project.org/.
LON-CAPA will accept two pre-named arrays inside the answerblock for the computer
algebra system: RESPONSE and LONCAPALIST. RESPONSE contains the student input
by comman-separated entities, for example, if ”3,42,17” is entered by the student, RE-
SPONSE[2] would be 42. LONCAPALIST is built from the arguments passed in an array
args which is assigned a array value from the script.
The answer tag contains the Maxima command (and syntax) that are passed to Maxima
aftertheRESPONSE and LONCAPALISTvaluesare substituted. (See examplebelow). The
answerdisplay variable contains what is displayed when the problem is in ”Show Answer”
mode. You will want to include this field so that the students can see the correct answer
after the ”Show Answer Date” configured when the problem is assigned in the course space.
Also note the description in the postanswerdate tag that is displayed after the answer date.
The following example illustrates this.
<problem>
<script type="loncapa/perl">
$a1 = random(-6,6,4);
$a2 = random(-6,6,4);
$n1 = random(3,11,2);
$n2 = random(2,10,2);
45
7 AUTHORING NUMERICAL, FORMULA, CUSTOM RESPONSE QUESTIONS
47
$function = "$a1*cos($n1*x)+$a2*sin($n2*x)";
# reformat next two lines as single line if you copy/paste into a script
$example=&xmlparse(’An example would be
<m eval="on">$(sin($n1\cdot x)+cos($n2\cdot x))/\sqrt{2}$</m>’);
</script>
<startouttext />
Give an example of a function
<ol>
<li>
which is orthogonal to <algebra>$function</algebra> with respect to the
scalar product
<m>
\[<g \mid h> =
\frac{1}{\pi} \int_{-\pi}^{\pi}dx g(x) \cdot h(x)\]
</m>
</li>
<li>
whose norm is 1.
</li>
</ol>
<endouttext />
<mathresponse answerdisplay="$example" cas="maxima" args="$function">
<answer>
overlap:integrate((RESPONSE[1])*(LONCAPALIST[1]),x,-%pi,%pi)/%pi;
norm:integrate((RESPONSE[1])*(RESPONSE[1]),x,-%pi,%pi)/%pi;
is(overlap=0 and norm=1);
</answer>
<textline readonly="no" size="50" />
<hintgroup showoncorrect="no">
<mathhint name="ortho" args="$function" cas="maxima">
<answer>
overlap: integrate((LONCAPALIST[1])*(RESPONSE[1]),x,-%pi,%pi)/%pi;
is(not overlap = 0);
</answer>
</mathhint>
<mathhint name="norm" args="$function" cas="maxima">
<answer>
norm: integrate((RESPONSE[1])*(RESPONSE[1]),x,-%pi,%pi)/%pi;
is(not norm = 1);
</answer>
</mathhint>
<hintpart on="norm">
<startouttext />
51
7 AUTHORING NUMERICAL, FORMULA, CUSTOM RESPONSE QUESTIONS
48
The function you have provided does not have a norm of one.
<endouttext />
</hintpart>
<hintpart on="ortho">
<startouttext />
The function you have provided is not orthogonal.
<endouttext />
</hintpart>
</hintgroup>
</mathresponse>
<postanswerdate>
<startouttext />
<p>
Note that with respect to the above norm, <m>$\cos(nx)$</m> is perpendicular
to <m>$\sin(nx)$</m> and perpendicular to <m>$\cos(mx)$</m> for
<m>$n\ne m$</m>.
</p>
<endouttext />
</postanswerdate>
</problem>
7.12 Custom Response Problems
Custom Response is a way to have a problem graded based on an algorithm. The use of
this response type is generally discouraged, since the responses will not be analyzable by the
LON-CAPA statistics tools.
For a single textfield, the student’s answer will be in a variable $submission. If the
Custom Response has multiple textfields, the answers will be in an array reference, and can
be accessed as $$submission[0], $$submission[1], etc.
The student answer needs to be evaluated by Perl code inside the < answer>-tag. Cus-
tom Response needs to include an algorithm that determines and returns a standard LON-
CAPA response. The most common LON-CAPA responses are:
• EXACT
ANS: return if solved exactly correctly
• APPROX
ANS: return if solved approximately
• INCORRECT: return if not correct, uses up a try
• ASSIGNED
SCORE: partial credit (also return the credit factor,
e.g. return(ASSIGNED
SCORE,0.3);)
• SIG
FAIL, NO
UNIT, EXTRA
ANSWER, MISSING
ANSWER, BAD
FORMULA,
WANTED
NUMERIC, WRONG
FORMAT: return if not correct for different reasons,
does not use up a try
52
7 AUTHORING NUMERICAL, FORMULA, CUSTOM RESPONSE QUESTIONS
49
The answerdisplay is shown instead of the student response in ’show answer’ mode after
the answer date. The following example illustrates this:
<problem>
<startouttext />Accept an answer of around 90 or -90<endouttext />
<customresponse answerdisplay="something near 90 or -90">
<answer type="loncapa/perl">
# This examples uses perl ’regular expressions’ for string evaluation.
# Consult a perl reference for help understanding the regular expressions.
# We do not want a vector
if ($submission=~/\,/) { return ’EXTRA_ANSWER’; }
# Need a numerical answer here
if ($submission!~/^[\d\.\-\e]+$/i) { return ’WANTED_NUMERIC’; }
$difference=abs(90-abs($submission));
if ($difference==0) { return ’EXACT_ANS’; }
if ($difference < 0.1) { return ’APPROX_ANS’; }
return ’INCORRECT’;</answer>
<textline readonly="no" />
</customresponse>
</problem>
Full list of possible return codes:
• EXACT
ANS: student is exactly correct
• APPROX
ANS: student is approximately correct
• NO
RESPONSE: student submitted no response
• MISSING
ANSWER: student submitted some but not all parts of a response
• EXTRA
ANSWER: student submitted a vector of values when a scalar was expected
• WANTED
NUMERIC: expected a numeric answer and didn’t get one
• SIG
FAIL: incorrect number of Significant Figures
• UNIT
FAIL: incorrect unit
• UNIT
NOTNEEDED: submitted a unit when one shouldn’t
• UNIT
INVALID
INSTRUCTOR: the unit provided by the author of the problem is
unparsable
• UNIT
INVALID
STUDENT: the unit provided by the student is unparasable
• UNIT
IRRECONCIBLE: the unit from the student and the instructor are of different
types
• NO
UNIT: needed a unit but none was submitted
43
8 AUTHORING DYNAMICALLY GENERATED PLOTS
50
• BAD
FORMULA: syntax error in submitted formula
• WRONG
FORMAT: student submission did not have the expected format
• INCORRECT: answer was wrong
• SUBMITTED: submission wasn’t graded
• DRAFT: submission only stored
• MISORDERED
RANK: student submitted a poorly order rank response
• ERROR: unable to get a grade
• ASSIGNED
SCORE: partial credit; the customresponse needs to return the award
followed by the partial credit factor
• TOO
LONG: answer submission was deemed too long
• INVALID
FILETYPE: student tried to upload a file that was of an extension that was
not specifically allowed
• EXCESS
FILESIZE: student uploaded file(s) with a combined size that exceeded the
amount allowed
• COMMA
FAIL: answer requires the use of comma grouping and it wasn’t provided or
was incorrect
8 Authoring Dynamically Generated Plots
The gnuplot LON-CAPA tag allows an author to design a plot which will be created pro-
gramatically at the time when it is requested for display by a student. This is intended for
use in homework problems where a distinct plot should be rendered for each student. It can
be used in conjunction with a script tag to generate curve data for random plots. If you are
using static data a dynamically generated plot is not appropriate because of the overhead
associated with generating the plot. In that case, use a picture (see “Adding Picture” section
5.3.2).
The easiset way to create a template for a gnuplot tag is to use the colorful problem
editor, and select GnuPlot from the Insert dropdown menu. Thereafter the boxes may
be filled using this documentation to assist you. By default, only the parent gnuplot tag
and the child curve tag are created by when the plot is inserted into a problem using the
colorful editor. Other tags can be added to decorate and polish your plot using the Insert:
dropdown provided by the colorful editor.
The following gnuplot parameters may be set:
• brief description of the plot This text is used as the alt value of the img tag
used to display the plot on a web page.
Documents you may be interested
Documents you may be interested