help logoLON-CAPA Help

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 R problems, 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 or .

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, RESPONSE[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 after the RESPONSE and LONCAPALIST values are substituted. (See example below). 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.

  <script type="loncapa/perl">
$a1 = random(-6,6,4);
$a2 = random(-6,6,4);
$n1 = random(3,11,2);
$n2 = random(2,10,2);
$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>');

<startouttext />
  Give an example of a function
        which is orthogonal to <algebra>$function</algebra> with respect to the
        scalar product
           \[<g \mid h> =
               \frac{1}{\pi} \int_{-\pi}^{\pi}dx g(x) \cdot h(x)\]
        whose norm is 1.
<endouttext />

<mathresponse answerdisplay="$example" cas="maxima" args="$function">
is(overlap=0 and norm=1);
    <textline readonly="no" size="50" />
    <hintgroup showoncorrect="no">
        <mathhint name="ortho" args="$function" cas="maxima">
overlap: integrate((LONCAPALIST[1])*(RESPONSE[1]),x,-%pi,%pi)/%pi;
is(not overlap = 0);
        <mathhint name="norm" args="$function" cas="maxima">
norm: integrate((RESPONSE[1])*(RESPONSE[1]),x,-%pi,%pi)/%pi;
is(not norm = 1);
        <hintpart on="norm">
           <startouttext />
The function you have provided does not have a norm of one.
           <endouttext />
        <hintpart on="ortho">
            <startouttext />
The function you have provided is not orthogonal.
            <endouttext />

    <startouttext />
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>.
    <endouttext />