[LON-CAPA-users] Forcing a sigma solution

Seema Ali sali at vsb.bc.ca
Tue Mar 20 21:55:44 EDT 2012


I'm working on creating a question that lists the terms of a finite sum and asking the students to enter a solution using sigma notation.  I know you can use the sum() function but I was wondering if it possible to make sure that the students enter a "valid" solution.


Example: ?5+10?15+20?25+30?35+40 

Some examples of valid solutions:
sum(5*n*(-1)^n,n,1,8)
sum(5*(n-1)*(-1)^(n-1),n,2,9)
sum(5*(n+1)*(-1)^(n+1),n,0,7)
5*sum(n*(-1)^n,n,1,8)
sum(n*(-1)^n,n,1,8)*5
plus other variations

Some examples of not valid solutions:
sum(0,n,1,8) + 20
sum(1,n,1,20)
20
plus other variations

Is it possible to have a question like this?  Below is the code that I have so far.  Keep in mind that it is still a work 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 = $firsterm;

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


if($firstterm>0)
{
  $answer = "-1*".$answer;
}



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);
}

  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;</script><startouttext /><instructions></instructions><endouttext /><startouttext /><m eval='on'>\[ \Large $sumdisplay \]</m>
base=$base <br />
numterm=$numterms <br />
total = $total<br />
style = $termstyle<br />
answer = $answer<br /><endouttext />
<mathresponse cas="maxima">
    <answer></answer>
    <textline readonly="no" />
    
</mathresponse>
</problem>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.lon-capa.org/pipermail/lon-capa-users/attachments/20120320/18f25486/attachment.html>


More information about the LON-CAPA-users mailing list