<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<META NAME="Generator" CONTENT="MS Exchange Server version 6.5.7654.12">
<TITLE>RE: [LON-CAPA-users] Forcing a sigma solution</TITLE>
</HEAD>
<BODY>
<!-- Converted from text/plain format -->

<P><FONT SIZE=2>Hi,<BR>
<BR>
I think I got it but there are a couple of things with the text boxes. <BR>
<BR>
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.<BR>
<BR>
2.  I'm not sure how to make the placement of the text boxes better.<BR>
<BR>
The code below is still in progress. <BR>
<BR>
Thanks.<BR>
<BR>
<problem><BR>
<BR>
<script type="loncapa/perl">$base      = &random(2,6,1);<BR>
$exponent  = &random(2,3,1);<BR>
<BR>
$firstterm = &random(-1,1,2)* $base;<BR>
$numterms  = &random(5,9,1);<BR>
$termstyle = &random(0,1,1); #determine if the term is base^n(-1)^m, or mn(-1)^p<BR>
<BR>
#$termstyle = 0;<BR>
<BR>
$term = $firstterm;<BR>
$sumdisplay  = $term;<BR>
$total = $firstterm;<BR>
#$total = 0;<BR>
<BR>
$removetotal = "$total,";<BR>
<BR>
<BR>
#calculate the answer<BR>
$answer = &choose($termstyle+1, "sum((-$base)^n,n,1,$numterms)","sum($base*n*(-1)^n,n,1,$numterms)");<BR>
<BR>
<BR>
if($firstterm>0)<BR>
{<BR>
  $answer = "-1*".$answer;<BR>
}<BR>
<BR>
<BR>
<BR>
for($i=1; $i<$numterms-1; $i++)<BR>
{<BR>
  if($term>0)<BR>
  {<BR>
    $sumdisplay .= ' - ';<BR>
  }<BR>
  else<BR>
  {<BR>
    $sumdisplay .= ' + ';<BR>
  }<BR>
 <BR>
  if($termstyle==0)<BR>
  {<BR>
    $term*= -1 * $base;         #term = base^n<BR>
   <BR>
  }<BR>
  else<BR>
  {<BR>
    #$term = (-1)**($i) * $base *($i+1 ); #term = mn(-1)^n<BR>
   if($firstterm>0)<BR>
   {<BR>
      $term =(-1)**($i) * $base *($i+1 ); #term = mn(-1)^n<BR>
<BR>
   }<BR>
   else<BR>
   {<BR>
      $term =(-1)**($i+1) * $base *($i+1 ); #term = mn(-1)^n<BR>
   }<BR>
<BR>
<BR>
  }<BR>
  $total += $term;<BR>
  $sumdisplay .= abs($term);<BR>
$removetotal .= "$total, ";<BR>
}<BR>
<BR>
  if($term>0)<BR>
  {<BR>
    $sumdisplay .= ' - ';<BR>
  }<BR>
  else<BR>
  {<BR>
    $sumdisplay .= ' + ';<BR>
  }<BR>
<BR>
  if($termstyle==0)<BR>
  {<BR>
    #$term = (-1*$base)**($numterms);  #term = base^n<BR>
    $term *= -1*$base;<BR>
  }<BR>
  else<BR>
  {<BR>
    $term = (-1)**($numterms) * $base*($numterms);  #term = mn(-1)^n<BR>
  }<BR>
<BR>
  $sumdisplay .= abs($term);<BR>
  $total += $term;<BR>
$removetotal .="$total";</script><BR>
<BR>
<startouttext /><BR>
Given a sum with the expected result.<BR>
<BR>
<BR>
<BR>
<instructions></instructions><endouttext /><startouttext /><m eval='on'>\[ \Large $sumdisplay \]</m><BR>
<BR>
<br /><br /><BR>
base=$base <br /><BR>
numterm=$numterms <br /><BR>
total = $total<br /><BR>
totalsteps = $removetotal<br /><BR>
style = $termstyle<br /><BR>
answer = $answer<br /><BR>
<endouttext /><BR>
<BR>
<customresponse answerdisplay="$sample"><BR>
<startouttext /><table><tr><td><endouttext /><BR>
    <textline size="3" readonly="no" /><BR>
<startouttext /></td><td></td></tr><BR>
<BR>
<tr><td><font size="+6">&Sigma;</font></td><td><endouttext /><BR>
    <textline readonly="no" /><BR>
<startouttext /></td></tr><tr><td><endouttext /><BR>
    <textline readonly="no" size="1" /><BR>
<startouttext />=<endouttext /><BR>
    <textline readonly="no" size="3" /><BR>
<startouttext /></td><td></td></tr></table><endouttext /><BR>
<answer type="loncapa/perl">$upper=$$submission[0];<BR>
$term=$$submission[1];<BR>
$vari=$$submission[2];<BR>
$lower=$$submission[3];<BR>
<BR>
$position  = $lower + &random(100,200,1);<BR>
<BR>
<BR>
#correct number of terms<BR>
if($upper - $lower != $numterms-1) { return 'INCORRECT'; }<BR>
<BR>
#alternating series<BR>
$termNsign = &cas('maxima',"ev($term,$vari=$position)/abs(ev($term,$vari=$position))");<BR>
$termN1sign= &cas('maxima',"ev($term,$vari=$position+1)/abs(ev($term,$vari=$position+1))");<BR>
if($termNsign=~/^Error/ || $termN1sign=~/^Error/) { return 'BAD_FORMULA'; }<BR>
elsif($termNsign==$termN1sign) { return 'INCORRECT'; }<BR>
<BR>
#not a constant term formula<BR>
$termN  = &cas('maxima', "abs(ev($term,$vari=$position))");<BR>
$termN1 = &cas('maxima', "abs(ev($term,$vari=$position+1))");<BR>
if($termN == $termN1) { return 'INCORRECT'; }<BR>
<BR>
<BR>
#term has correct properties, eg geometric, arithmetic, etc<BR>
if($termstyle==0) #geometric<BR>
{<BR>
  $case1 = &cas('maxma', "ev($term,$vari=$lower+1)   / ev($term,$vari=$lower)");<BR>
  $case2 = &cas('maxma', "ev($term,$vari=$position+1)/ ev($term,$vari=$position)");<BR>
}<BR>
elsif($termstyle==1) #arithmetic-ish<BR>
{<BR>
  $case1 = &cas('maxima', "abs(ev($term,$vari=$lower+1))   - abs(ev($term, $vari=$lower))");<BR>
  $case2 = &cas('maxima', "abs(ev($term,$vari=$postion+1)) - abs(ev($term, $vari=$position))");<BR>
}<BR>
if($case1!=$case2) { return 'INCORRECT'; }<BR>
<BR>
<BR>
$sum=&cas('maxima',"sum($term,$vari,$lower,$upper)");<BR>
if ($sum=~/^Error/) { return 'BAD_FORMULA'; }<BR>
if ($sum==$total) { return 'EXACT_ANS'; }<BR>
return 'INCORRECT';</answer><BR>
<BR>
  <BR>
</customresponse><BR>
<BR>
</problem><BR>
<BR>
<BR>
<BR>
<BR>
<BR>
-----Original Message-----<BR>
From: lon-capa-users-bounces@mail.lon-capa.org on behalf of Gerd Kortemeyer<BR>
Sent: Fri 3/23/2012 3:31 AM<BR>
To: Discussion list for LON-CAPA users<BR>
Subject: Re: [LON-CAPA-users] Forcing a sigma solution<BR>
<BR>
Hi,<BR>
<BR>
On Mar 22, 2012, at 11:35 PM, Seema Ali wrote:<BR>
><BR>
> 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<BR>
<BR>
Yes, I would definitely go with Justin's idea.<BR>
<BR>
<BR>
> 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.<BR>
<BR>
You can have several boxes within the same customresponse.<BR>
<BR>
<BR>
>  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.<BR>
><BR>
> 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.<BR>
<BR>
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.<BR>
<BR>
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.<BR>
<BR>
I'll be happy to work some more on this later today, just let me know what you need.<BR>
<BR>
- Gerd.<BR>
<BR>
<problem><BR>
<script type="loncapa/perl"><BR>
$answer=&random(3,18,1);<BR>
</script><BR>
<BR>
<startouttext /><BR>
Given a sum with the expected result.<BR>
<endouttext /><BR>
<BR>
<customresponse answerdisplay="$sample"><BR>
<startouttext /><table><tr><td><endouttext /><BR>
    <textline size="3" readonly="no" /><BR>
<startouttext /></td><td></td><td></td></tr><tr><td><font size="+6">&Sigma;</font></td><td><endouttext /><BR>
    <textline readonly="no" /><BR>
<startouttext /></td><td>=$answer</td></tr><tr><td><endouttext /><BR>
    <textline readonly="no" size="1" /><BR>
<startouttext />=<endouttext /><BR>
    <textline readonly="no" size="3" /><BR>
<startouttext /></td><td></td><td></td></tr></table><endouttext /><BR>
<answer type="loncapa/perl"><BR>
$upper=$$submission[0];<BR>
$term=$$submission[1];<BR>
$vari=$$submission[2];<BR>
$lower=$$submission[3];<BR>
<BR>
$sum=&cas('maxima',"sum($term,$vari,$lower,$upper)");<BR>
if ($sum=~/^Error/) { return 'BAD_FORMULA'; }<BR>
if ($sum==$answer) { return 'EXACT_ANS'; }<BR>
return 'INCORRECT';</answer><BR>
<BR>
   <BR>
</customresponse><BR>
<BR>
</problem><BR>
<BR>
<BR>
<BR>
_______________________________________________<BR>
LON-CAPA-users mailing list<BR>
LON-CAPA-users@mail.lon-capa.org<BR>
<A HREF="http://mail.lon-capa.org/mailman/listinfo/lon-capa-users">http://mail.lon-capa.org/mailman/listinfo/lon-capa-users</A><BR>
</FONT>
</P>

</BODY>
</HTML>