[LON-CAPA-users] Forcing a sigma solution

Justin Gray jgray at math.sfu.ca
Tue Mar 20 22:12:26 EDT 2012


I suggest that you approach coding this problem as follows. Ask the student
to input the limits of summation and the function that you are summing over
as an ordered triple into a mathresponse problem. That is, tell the student
to express the answer in the form  <m>$\sum_{n=a}^{b}f(n)$</m> but just ask
them to input the ordered triple a,b,f(n). Then determine if
sum(f(n),n,a,b) is equivalent to the desired sum in Maxima.

Justin

Justin Gray | Senior Lecturer
Department of Mathematics | Simon Fraser University
8888 University Drive, Burnaby | V5A 1S6 | Canada
Tel: +1 778.782.4237




On Tue, Mar 20, 2012 at 6:55 PM, Seema Ali <sali at vsb.bc.ca> wrote:

> **
>
> 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>
>
> _______________________________________________
> 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/20120320/470d0b85/attachment.html>


More information about the LON-CAPA-users mailing list