# [LON-CAPA-users] Forcing a sigma solution

Seema Ali sali at vsb.bc.ca
Fri Mar 23 13:29:04 EDT 2012

```Hi,

I think I got it but there are a couple of things with the text boxes.

1.  I would like the text box that contains the formula for the term to have the equation viewer/editor Java thing available to the students.  So that they can see what their formula looks like.

2.  I'm not sure how to make the placement of the text boxes better.

The code below is still in progress.

Thanks.

<problem>

<script type="loncapa/perl">\$base      = &random(2,6,1);
\$exponent  = &random(2,3,1);

\$firstterm = &random(-1,1,2)* \$base;
\$numterms  = &random(5,9,1);
\$termstyle = &random(0,1,1); #determine if the term is base^n(-1)^m, or mn(-1)^p

#\$termstyle = 0;

\$term = \$firstterm;
\$sumdisplay  = \$term;
\$total = \$firstterm;
#\$total = 0;

\$removetotal = "\$total,";

\$answer = &choose(\$termstyle+1, "sum((-\$base)^n,n,1,\$numterms)","sum(\$base*n*(-1)^n,n,1,\$numterms)");

if(\$firstterm>0)
{
}

for(\$i=1; \$i<\$numterms-1; \$i++)
{
if(\$term>0)
{
\$sumdisplay .= ' - ';
}
else
{
\$sumdisplay .= ' + ';
}

if(\$termstyle==0)
{
\$term*= -1 * \$base;         #term = base^n

}
else
{
#\$term = (-1)**(\$i) * \$base *(\$i+1 ); #term = mn(-1)^n
if(\$firstterm>0)
{
\$term =(-1)**(\$i) * \$base *(\$i+1 ); #term = mn(-1)^n

}
else
{
\$term =(-1)**(\$i+1) * \$base *(\$i+1 ); #term = mn(-1)^n
}

}
\$total += \$term;
\$sumdisplay .= abs(\$term);
\$removetotal .= "\$total, ";
}

if(\$term>0)
{
\$sumdisplay .= ' - ';
}
else
{
\$sumdisplay .= ' + ';
}

if(\$termstyle==0)
{
#\$term = (-1*\$base)**(\$numterms);  #term = base^n
\$term *= -1*\$base;
}
else
{
\$term = (-1)**(\$numterms) * \$base*(\$numterms);  #term = mn(-1)^n
}

\$sumdisplay .= abs(\$term);
\$total += \$term;
\$removetotal .="\$total";</script>

<startouttext />
Given a sum with the expected result.

<instructions></instructions><endouttext /><startouttext /><m eval='on'>\[ \Large \$sumdisplay \]</m>

<br /><br />
base=\$base <br />
numterm=\$numterms <br />
total = \$total<br />
totalsteps = \$removetotal<br />
style = \$termstyle<br />
<endouttext />

<startouttext /><table><tr><td><endouttext />
<textline size="3" readonly="no" />
<startouttext /></td><td></td></tr>

<tr><td><font size="+6">Σ</font></td><td><endouttext />
<startouttext /></td></tr><tr><td><endouttext />
<textline readonly="no" size="1" />
<startouttext />=<endouttext />
<textline readonly="no" size="3" />
<startouttext /></td><td></td></tr></table><endouttext />
\$term=\$\$submission[1];
\$vari=\$\$submission[2];
\$lower=\$\$submission[3];

\$position  = \$lower + &random(100,200,1);

#correct number of terms
if(\$upper - \$lower != \$numterms-1) { return 'INCORRECT'; }

#alternating series
\$termNsign = &cas('maxima',"ev(\$term,\$vari=\$position)/abs(ev(\$term,\$vari=\$position))");
\$termN1sign= &cas('maxima',"ev(\$term,\$vari=\$position+1)/abs(ev(\$term,\$vari=\$position+1))");
if(\$termNsign=~/^Error/ || \$termN1sign=~/^Error/) { return 'BAD_FORMULA'; }
elsif(\$termNsign==\$termN1sign) { return 'INCORRECT'; }

#not a constant term formula
\$termN  = &cas('maxima', "abs(ev(\$term,\$vari=\$position))");
\$termN1 = &cas('maxima', "abs(ev(\$term,\$vari=\$position+1))");
if(\$termN == \$termN1) { return 'INCORRECT'; }

#term has correct properties, eg geometric, arithmetic, etc
if(\$termstyle==0) #geometric
{
\$case1 = &cas('maxma', "ev(\$term,\$vari=\$lower+1)   / ev(\$term,\$vari=\$lower)");
\$case2 = &cas('maxma', "ev(\$term,\$vari=\$position+1)/ ev(\$term,\$vari=\$position)");
}
elsif(\$termstyle==1) #arithmetic-ish
{
\$case1 = &cas('maxima', "abs(ev(\$term,\$vari=\$lower+1))   - abs(ev(\$term, \$vari=\$lower))");
\$case2 = &cas('maxima', "abs(ev(\$term,\$vari=\$postion+1)) - abs(ev(\$term, \$vari=\$position))");
}
if(\$case1!=\$case2) { return 'INCORRECT'; }

\$sum=&cas('maxima',"sum(\$term,\$vari,\$lower,\$upper)");
if (\$sum=~/^Error/) { return 'BAD_FORMULA'; }
if (\$sum==\$total) { return 'EXACT_ANS'; }

</customresponse>

</problem>

-----Original Message-----
From: lon-capa-users-bounces at mail.lon-capa.org on behalf of Gerd Kortemeyer
Sent: Fri 3/23/2012 3:31 AM
To: Discussion list for LON-CAPA users
Subject: Re: [LON-CAPA-users] Forcing a sigma solution

Hi,

On Mar 22, 2012, at 11:35 PM, Seema Ali wrote:
>
> I'm not sure how to extract information from an ordered triple.  I'm also concerned that students might have a hard time entering the 3 pieces of information correctly.  So I tried to implement Justin's idea

Yes, I would definitely go with Justin's idea.

> in a different way by having 3 textboxes, however each text box requires an answer and I would like to use the Math Response to see of a small set of conditions have been satisfied to determine if the response is correct.

You can have several boxes within the same customresponse.

>  I also don't really know how to extract the 3 pieces of information and am hoping that RESPONSE[1], RESPONSE[2] AND RESPONSE[3] can be used for the 3 text boxes.
>
> Below is a copy of the problem with the 3 textboxes.  I'm stuck on the coding part. If anyone has a similar question that uses information from a few different textboxes to see if the answer is correct or another way to implement this type of question and is willing to share, I'd greatly appreciate it.

You can have more than one textbox within the same response, no problem. I did not have much time this morning, but I started coding something for you. It's sort of your setup, but inside-out. It brings up a customresponse with four textboxes and shows how to access the values from within the answer-script.

Inside customresponse, I would then use &cas()-calls to evaluate the sum, using MAXIMA. I haven't done that part correctly (something's wrong), but it's just straight MAXIMA.

I'll be happy to work some more on this later today, just let me know what you need.

- Gerd.

<problem>
<script type="loncapa/perl">
</script>

<startouttext />
Given a sum with the expected result.
<endouttext />

<startouttext /><table><tr><td><endouttext />
<textline size="3" readonly="no" />
<startouttext /></td><td></td><td></td></tr><tr><td><font size="+6">Σ</font></td><td><endouttext />
<textline readonly="no" size="1" />
<startouttext />=<endouttext />
<textline readonly="no" size="3" />
<startouttext /></td><td></td><td></td></tr></table><endouttext />
\$upper=\$\$submission[0];
\$term=\$\$submission[1];
\$vari=\$\$submission[2];
\$lower=\$\$submission[3];

\$sum=&cas('maxima',"sum(\$term,\$vari,\$lower,\$upper)");
if (\$sum=~/^Error/) { return 'BAD_FORMULA'; }
if (\$sum==\$answer) { return 'EXACT_ANS'; }

</customresponse>

</problem>

_______________________________________________
LON-CAPA-users mailing list
LON-CAPA-users at mail.lon-capa.org
http://mail.lon-capa.org/mailman/listinfo/lon-capa-users
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.lon-capa.org/pipermail/lon-capa-users/attachments/20120323/3e1d8bdb/attachment-0001.html>
```