WeBWorK Problems

problem with problem

problem with problem

by Zak Zarychta -
Number of replies: 4
the following script marks the second problem incorrect when the first part is correct regardless of the answer being incorrect/correct.

Also If the answer to the first part is incorrect and the second part correct then the the answer to the first part is marked incorrect whilst the second part is marked correct

What am i missing here ?

DOCUMENT();
loadMacros(
"PGstandard.pl",
"parserFormulaUpToConstant.pl");

Context("Numeric")->variables->are(x=>"Real");

$fx = Formula("x**2 + 3*x");
$f = FormulaUpToConstant("x**3/3 + 3/2*x**2 + C");
$gx = Formula("1/x**2 + 1/x");
$g = FormulaUpToConstant("-1/x + ln(x) + C");

Context()->texStrings;
BEGIN_TEXT
Evaluate the following integrals
$PAR
a) \(\int \left( $fx \right) dx = \)
\{ ans_rule(15) \}
$BR
END_TEXT
Context()->normalStrings;

$ans = $f;
ANS( $ans->cmp() );

Context()->texStrings;
BEGIN_TEXT
$PAR
b) \(\int \left( $gx \right) dx = \)
\{ ans_rule(15) \}
END_TEXT
Context()->normalStrings;

$ans = $g;
ANS( $ans->cmp() );

ENDDOCUMENT();
In reply to Zak Zarychta

Re: problem with problem

by Darwyn Cook -
Not sure that I could come up with as good an explanation as Davide will, but I would guess it has something to do with pointers and how the problem is compiled.
If you are just interested in getting the problem working I would get rid of $ans altogether replacing

$ans = $f;
ANS( $ans->cmp() );

with
ANS($f->cmp());

similarly for $g so that you get something like the following (untested) code:

DOCUMENT();
loadMacros(
"PGstandard.pl",
"parserFormulaUpToConstant.pl");

Context("Numeric")->variables->are(x=>"Real");

$fx = Formula("x**2 + 3*x");
$f = FormulaUpToConstant("x**3/3 + 3/2*x**2 + C");
$gx = Formula("1/x**2 + 1/x");
$g = FormulaUpToConstant("-1/x + ln(x) + C");


Context()->texStrings;
BEGIN_TEXT
Evaluate the following integrals
$PAR
a) \(\int \left( $fx \right) dx = \)
\{ ans_rule(15) \}
$BR
$PAR
b) \(\int \left( $gx \right) dx = \)
\{ ans_rule(15) \}
END_TEXT
Context()->normalStrings;

ANS( $f->cmp() );
ANS( $g->cmp() );

ENDDOCUMENT();
In reply to Darwyn Cook

Re: problem with problem

by Zak Zarychta -
Tried it,...same problem.
In reply to Zak Zarychta

Re: problem with problem

by Gavin LaRose -
Hi Zak,

I'm unable to duplicate exactly the behavior you describe, but I am seeing some oddities in the grading that the problem produces. That said, it appears that if I take the restriction on the variables off in the Context call things behave as expected (that is, replace Context("Numeric")->variables->are(x=>"Real") with Context("Numeric"); in that x is the default variable this should be fine).

Interestingly, I'm seeing sporadic instances of behavior similar to that which you report in the following circumstances:
(1) if I include the variables specification;
(2) if I specify limits for the variable; and
(3) if I specify test_points or test_at for the formula $g.

I don't think these should have an impact on the answer evaluation, because the FormulaUpToConstant answer evaluator is copying the context to add a new variable corresponding to the student's constant of integration, but it may be in this case that there's something subtle going on that I'm not anticipating.

If someone else doesn't have time in the next day or so to go poking at the actual evaluator code to see what it's doing I'll try to look at it and see if my somewhat limited understanding of Davide's magic is equal to figuring out what's going on.

Gavin
In reply to Gavin LaRose

Re: problem with problem

by Zak Zarychta -
The problem persists when the replacment you suggest is made.

Since you are not seeing this behaviour could this mean that there is something awry with the installation of WW on the local server?