In the code, this is simple, and I just put an 'if' statement to change the answer accordingly. However, how do I write my solution? The first part of the solution is the same, but then, at the end, I would change the last line depending on whether the series started at 'n=1' or 'n=2'. Is there a way to do that? Some sort of statement that writes one thing in the solution if n=1, and another thing if n=2.
Here is my current code:
DOCUMENT();
loadMacros(
"PGstandard.pl",
"PGML.pl",
"PGcourse.pl"
);
TEXT(beginproblem());
$a=random(2,3,1);
$b=random(4,8,1);
$c=random(1,2,1);
$sum0=1/(1 - $a/$b);
$sum1=$sum0 - 1;
$sum2=$sum1 - $a/$b;
if ($c == 1)
{ $answer = $sum1; }
else
{ $answer = $sum2; }
BEGIN_PGML
Determine whether the following series is convergent or divergent.
If it is convergent, enter the sum of the series.
If it is divergent, enter "divergent" (without quotes).
[` \displaystyle \sum_{n= [$c] }^{\infty} \frac{[$a]^n}{[$b]^n} = `] [_____________]{$answer}
END_PGML
BEGIN_PGML_SOLUTION
The series simplifies as [` \displaystyle \sum_{n= [$c] }^{\infty} \frac{[$a]^n}{[$b]^n} = \sum_{n= [$c] }^{\infty} \left( \frac{[$a]}{[$b]} \right)^n `].
Since the absolute value of the ratio [` \displaystyle \frac{[$a]}{[$b]} `] is less than 1, the series is convergent.
The full sum starting at [` n=0 `] is [` \displaystyle \sum_{n=0}^{\infty} \left( \frac{[$a]}{[$b]} \right)^n = \frac1{\displaystyle 1 - \frac{[$a]}{[$b]} } `].
Therefore, [` \displaystyle \sum_{n= [$c] }^{\infty} \left( \frac{[$a]}{[$b]} \right)^n `] ….. TO BE FINISHED …..
END_PGML_SOLUTION
ENDDOCUMENT;