##DESCRIPTION ##ENDDESCRIPTION DOCUMENT(); # This should be the first executable line in the problem. loadMacros( "PGstandard.pl", # Standard macros for PG language "MathObjects.pl", #"source.pl", # used to display problem source button "contextIntegerFunctions.pl", "PGcourse.pl", # Customization file for the course ); TEXT(beginproblem()); $showPartialCorrectAnswers = 1; ############################################################## # # Setup # # Context("IntegerFunctions"); Context()->variables->are(n=>'Real'); # get rid of x as a variable -- only variable now is n $a_n = Formula("n*(n+1)/2"); # reference: http://webwork.maa.org/wiki/FormulaTestPoints $a_n->{test_points} = [[4],[6],[8]]; # this is awkward, but if there were two variables then the points # would be [[4,1],[5,2],[7,4]] etc. ############################################################## # # Text # # Context()->texStrings; #allows MathObjects to print in TeX BEGIN_TEXT What is an explicit expression for the sum of the first \(n\) positive integers? $BR \( a_n = \) \{ ans_rule(40) \} $PAR END_TEXT Context()->normalStrings; ############################################################## # # Answers # # ANS($a_n->cmp); ENDDOCUMENT(); # This should be the last executable line in the problem.
Is there a way to do this using a random number for the bottom of the binomial coefficient? I.e. asking the students to input the correct formula for C(n+$k,$k) where $k is a random value? So I assume I'd need to include a loop to get the function correct...?
Here is a variant of Mike's answer that will do what I think you are asking for. This uses a loop as you said. I used PGML for this, but you could use PG as Mike did if you must. I highly recommend switching to PGML though as that is the modern approach.
DOCUMENT();
loadMacros(
"PGstandard.pl",
"MathObjects.pl",
"PGML.pl",
"contextIntegerFunctions.pl",
"PGcourse.pl"
);
TEXT(beginproblem());
Context("IntegerFunctions");
Context()->variables->are(n => 'Real');
$k = random(2, 6);
$ans_str = "";
$ans_str .= "(n - $_)" for (1 .. $k);
$ans = Formula($ans_str)->with(test_points => [ map { [2 * $_] } 1 .. $k + 1 ]);
BEGIN_PGML
What is an explicit expression for [`C(n + [$k], [$k])`]?
[`C(n + [$k], [$k]) = `] [_]{$ans}{40}
END_PGML
ENDDOCUMENT();