PREP 2015 Question Authoring - Archived

Error 'Can't evaluate formula on test point'

Error 'Can't evaluate formula on test point'

by Daniele Arcara -
Number of replies: 2
I am working on a problem involving factorials, and I get errors related to evaluating the function. Of course, being a factorial, it can only be evaluated at positive integers. I tried to 'force' it to check it only at positive integers, but I keep getting an error saying 'Can't evaluate formula on test point (_)'.

Here is my code (you can see my several attempts at defining $h and 'forcing' the code to evaluate it at integers):

DOCUMENT();

loadMacros(
"PGstandard.pl",
"PGML.pl",
"MathObjects.pl",
"parserPopUp.pl",   # For multiple choice questions with a drop down menu
"PGcourse.pl"
);

TEXT(beginproblem());

Context("Numeric");
Context()->variables->add( n => 'Real' );     # To add a new variable

$a = random(2,5,1);

$f = Formula("($a**n)/((n+1)!)");
$g = Formula("($a**(n+1))/((n+2)!)");
# $h = $g / $f;
# $h->{test_points} = [[1],[2],[3],[4],[5]];
# $h = Formula("$g / $f")->with(test_points => [[2],[3],[4],[5],[6]]);
$h = Formula("(($a**(n+1))/((n+2)!)) / (($a**n)/((n+1)!))")->with(test_points => [[2],[3],[4],[5],[6]]);

$ans = 0;
$popup = PopUp(["?", "Convergent", "Divergent", "Unknown"], "Convergent");

BEGIN_PGML

Consider the series [`` \sum_{n=1}^{\infty} \frac{[$a]^n}{(n+1)!} ``]. 

The limit for the Ratio Test is
[`` \lim_{n \rightarrow \infty} ``] [______________]{$h} [` = `] [_____]{$ans} (insert both the quantity to evaluate and the answer for the limit).

The series is [________________]{$popup} (select "unknown" if the ratio test is inconclusive).

END_PGML

$showHint = 3;
BEGIN_PGML_HINT
Note that, if [`` a_n = \frac{[$a]^n}{(n+1)!} ``], then [`` a_{n+1} = \frac{[$a]^{n+1}}{(n+2)!} ``].
END_PGML_HINT

$showHint = 6;
BEGIN_PGML_HINT
Note that [` (n+2)! = (n+2) \cdot (n+1)! `]
END_PGML_HINT

BEGIN_PGML_SOLUTION

The limit for the Ratio Test is
[`` \lim_{n \rightarrow \infty} \frac{ \displaystyle \frac{[$a]^{n+1}}{(n+2)!} }{ \displaystyle \frac{[$a]^n}{(n+1)!} } = \lim_{n \rightarrow \infty} \frac{[$a]^{n+1}}{(n+2)!} \cdot \frac{(n+1)!}{[$a]^n} = \lim_{n \rightarrow \infty} \frac{[$a]^{n+1}}{[$a]^n} \cdot \frac{(n+1)!}{(n+2)!} = \lim_{n \rightarrow \infty} \frac{[$a]\cdot[$a]^n}{[$a]^n} \cdot \frac{(n+1)!}{(n+2)(n+1)!} = \lim_{n \rightarrow \infty} [$a] \cdot \frac1{n+2} = 0 < 1 ``].
Therefore, the series [`` \sum_{n=1}^{\infty} \frac{[$a]^n}{(n+1)!} ``] is convergent by the Ratio Test.

END_PGML_SOLUTION

ENDDOCUMENT;
In reply to Daniele Arcara

Re: Error 'Can't evaluate formula on test point'

by Davide Cervone -
Because you have done
    Context()->variables->add( n => 'Real' );
that means that the context has two variables (the original "x" and your new "n"). Because students could enter answers that include both variables, even though your answer only includes n, you need to provide values for both. So your test points need to look like
    test_points => [[2,1.2],[3,-.27],[4,.75],[5,.54],[6,-.93]]
or something similar.

On the other hand, since you don't use "x" in your problem, you might use

    Context()->variables->are( n => 'Real' );
to remove the "x" before adding the "n". That will make your test points be usable.

Alternatively, you could use

   Context()->variables->add(n => ['Real', limits => [1,10,1]]);
which causes the variable n to have a range from 1 to 10 in increments of 1 (I.e., integer values).
In reply to Davide Cervone

Re: Error 'Can't evaluate formula on test point'

by Daniele Arcara -
Thank you!

I think that I will use the last one, because I will soon have an assignment on power series where I will need both the 'n' and the 'x' as variables.