I'm creating questions where students need to work with equations containing infinite sums (generating functions in particular), where I want make sure students can do some basic manipulations that affect the lower limits of summation and the terms.
I have found two types of code for putting answer blanks in the upper and lower limits of summation, which I called Version 1 and Version 2 below. I took existing code and modified it in both cases. Modified Library/FortLewis/Authoring/Templates/IntegralCalc/LimitsOfIntegration1_PGML.pg for Version 1 (authored 2015, from PGML tutorial) and modified Library/AlfredUniv/diffeq/series/ordinarypoints/OrdinaryPoint2fullyworked.pg for Version 2 (authored 2011)
Regarding using current styles and PGML, is Version 1 or Version 2 better?
Problem with Version (1): I don't know how to get the whole equation on one line. At the moment, each sum and each +,- = is on its own line.
Problem with Version (2): The term being summed is very far away from the summation sign, unless I put \hskip -20pt in front of the term. [see code for the first sum] This seems like a bit of hack which might cause problems?
Any suggestions would be greatly appreciated!
____________________________________________
########################################################################
DOCUMENT();
loadMacros(
"PGstandard.pl", # Standard macros for PG language
"MathObjects.pl",
"PGML.pl",
"PGchoicemacros.pl", # NchooseK defined here
"contextIntegerFunctions.pl", # need for P(n,k) and C(n,k);
"AnswerFormatHelp.pl",
"PGunion.pl",
"answerHints.pl", #only need if using answer hint in answer checker
"PGcourse.pl", # Customization file for the course
"Alfredmacros.pl",
);
# Print problem number and point value (weight) for the problem
TEXT(beginproblem());
# Show which answers are correct and which ones are incorrect, set to 0 for no information
$showPartialCorrectAnswers = 1;
##############################################################
#
# Setup
#
#
Context("Numeric");
#Context("Numeric")->variables->are(n=>"Real");
#Context()->flags->set(tolerance => 0.01);
$start1 = Compute("1");
$end1 = Compute("Infinity");
$start2 = Compute("1");
$end2 = Compute("Infinity");
$start3 = Compute("1");
$end3 = Compute("Infinity");
$start_alfred1 = Compute("1");
$end_alfred1 = Compute("Infinity");
$start_alfred2 = Compute("1");
$end_alfred2 = Compute("Infinity");
$start_alfred3 = Compute("1");
$end_alfred3 = Compute("Infinity");
#
# Display exponents nicely
#
$w = 1; # width of answer blanks for sums
Context()->texStrings;
if ($displayMode eq 'TeX') {
$showsum1 =
"\( \displaystyle \sum_{n = " . ans_rule($w) . "} ^{". ans_rule($w) . "} a_n x^n \)";
} else {
$showsum1 =
BeginTable(center=>0).
Row([
ans_rule($w).$BR.$BR.$BR.'\({\small n=}\) '.ans_rule($w),
'\( \displaystyle \hspace{-10ex}\sum a_n x^n\)'],
separation =>2).
EndTable();
}
if ($displayMode eq 'TeX') {
$showsum2 =
"\( \displaystyle \sum_{n = " . ans_rule($w) . "} ^{". ans_rule($w) . "}4a_{n-1} x^n \)";
} else {
$showsum2 =
BeginTable(center=>0).
Row([
ans_rule($w).$BR.$BR.$BR.'\({\small n=}\) '.ans_rule($w),
'\( \displaystyle \hspace{-10ex}\sum 4a_{n-1} x^n\)'],
separation =>2).
EndTable();
}
if ($displayMode eq 'TeX') {
$showsum3 =
"\( \displaystyle \sum_{n = " . ans_rule($w) . "} ^{". ans_rule($w) . "}2\cdot (3)^n x^n \)";
} else {
$showsum3 =
BeginTable(center=>0).
Row([
ans_rule($w).$BR.$BR.$BR.'\({\small n=}\) '.ans_rule($w),
'\( \displaystyle \hspace{-10ex}\sum 2\cdot (3)^n x^n\)'],
separation =>2).
EndTable();
}
Context()->normalStrings;
##############################################################
#
# Text
#
#
BEGIN_PGML
We are going to use the method of generating functions to solve the recurrence relation below.
>>[:: a_n +4a_{n-1} = 2 * 3^n, quad n >= 1 qquad qquad a_0 =5::]<<
Let [:: f(x) = Sum(n:0,infty; a_nx^n) ::] be the generating function for the sequence above. Then
Version (1). Not using Alfredmacros.pl
[$showsum1]*** [:+:] [$showsum2]*** [:= :] [$showsum3]***
Version (2). Using Alfredmacros.pl
[@ BeginTable(center=>0).
Row([ tablesum(sumvariable=>'\(n\)',width=>1, upper=>ans_rule(2)), '\(a_nx^n \)',
'\(+\)',
tablesum(sumvariable=>'\(n\)',width=>1, upper=>ans_rule(2)), '\(a_{n-1}x^n \)',
'\(=\)',
tablesum(sumvariable=>'\(n\)',width=>1, upper=>ans_rule(2)), '\(2\cdot 3^nx^n \)'],
separation=>1).
EndTable();
@]***
END_PGML
############################
# Answer evaluation
ANS( $end1->cmp() );
ANS( $start1->cmp() );
ANS( $end2->cmp() );
ANS( $start2->cmp() );
ANS( $end3->cmp() );
ANS( $start3->cmp() );
ANS( $start_alfred1->cmp() );
ANS( $end_alfred1->cmp() );
ANS( $start_alfred2->cmp() );
ANS( $end_alfred2->cmp() );
ANS( $start_alfred3->cmp() );
ANS( $end_alfred3->cmp() );
COMMENT('MathObject version. Uses PGML.');
ENDDOCUMENT();