WeBWorK Problems

Comparing MathObject Formulas

Comparing MathObject Formulas

by Ian Delbridge -
Number of replies: 5
Hi,

I'm working on a problem using some physics equations, and in one part I asked the student to solve a system of two equations for one of the variables in terms of the other variables. I simplified my answer a little bit when writing the answers so that it would be clear and easy to read when being presented to the user, but when I tried it out, an equivalent formula was not accepted as correct. I haven't had this problem before, but is there something I'm doing wrong or a way around this problem? I'm afraid that this sort of problem applies to many formula answers, and that the comparator is rejecting input equivalent to the answers. 

Here's a snippet of the code:
------------------------------------------------------------------------------
...
Context("Numeric");
Context()->variables->are(G => 'Real',
                          M => 'Real',
                          R => 'Real',
                          v => 'Real',
                          a => 'Real',);
...
Context()->normalStrings;

#################################################################
##ANSWERS SET 2##################################################

$ans1 = Compute("sqrt(G M /a)");
$ans2 = Compute("(a G M)^(1/4)");
$ans3 = NumberWithUnits("sqrt($Gwithout *$Mwithout /$awithout) m");
$ans4 = NumberWithUnits("($awithout *$Gwithout* $Mwithout)^(1/4) m/s");

ANS($ans1->cmp());
ANS($ans2->cmp());
ANS($ans3->cmp());
ANS($ans4->cmp());
...
---------------------------------------------------------------------------------
There's part of a screenshot in the attachment.
I typed sqrt(a*sqrt(G M /a)) as input for the record, but sqrt(sqrt(a G M)) works as well as (a G M)^(1/4). 

Again, thank you for any help.
Attachment screenshot.jpg
In reply to Ian Delbridge

Re: Comparing MathObject Formulas

by D. Brian Walton -
My experience suggests that this is almost certainly a problem of domain, which for MathObjects translates to the points at which the formulas are compared.

You naturally are thinking of a, G and M as always being positive values. But when WeBWorK checks your solutions, it randomly (or not so randomly) chooses points at which to compare the formulas. By default, some of these values are going to include negative values.

In the case that a<0 and GM < 0, the formula (aGM)^(1/4) is defined but sqrt(a*sqrt(GM/a)) is NOT defined.

You need to restrict your domain. See the following link http://webwork.maa.org/wiki/FormulaTestPoints

One possible solution would be:
Context()->variables->set(G=>{limits=>[0,1]}, 
                          M=>{limits=>[0,1]}, 
                          a=>{limits=>[0,1]});

Best wishes,
Brian Walton
In reply to D. Brian Walton

Re: Comparing MathObject Formulas

by Ian Delbridge -
I see, that makes a lot of sense!
I tried it out, and that works perfectly! I'll make sure to keep this facet of formula comparison in mind going forward. 
Thank you!

Gratefully,
Ian Delbridge

In reply to Ian Delbridge

Re: Comparing MathObject Formulas

by Alex Jordan -
I just have a minor observation. It might be appropriate to make G and M be constants rather than variables. (http://webwork.maa.org/wiki/Introduction_to_Contexts#Constants)

Ideally, something like G would be a constant with units, and students could interchangeably enter answers with "G", the numerical value in units of Nm^2/kg^2, or the numerical value in any other recognized units. But the functionality of units in WeBWorK isn't there yet.

I can't see the problem body, but if it is clear that SI units are in use, then making "G" be a constant could be a good idea (and maybe M too). It comes down to what feedback you would like a student to get if they entered "0.002858 (aM)^1/4" (which I think is correct in SI). Would you like them to just be told they are incorrect?
In reply to Alex Jordan

Re: Comparing MathObject Formulas

by Ian Delbridge -
We want students to have to manipulate symbols more, to practice rearranging equations without numbers, so I think it's best to keep G and M as variables for now, also because the students aren't expected to know any physics for this, even though it uses some physics equations. 

I'm writing a set of problems to help students enrolled in an introductory physics course with their math skills used in the class, specifically working with symbolic equations so that they will be able to solve a problem and at the end plug in the values given for the variables, rather than put them in as soon as possible.


In reply to Ian Delbridge

Re: Comparing MathObject Formulas

by Paul Pearson -
Hi Ian,

I would advocate using (named) constants in the context instead of variables.  The fewer variables there are in the context, the fewer variables there are to check during answer evaluation.  As a result of using fewer variables, the answer checker should be more robust and make fewer computations during answer checking.  I would recommend reading

http://webwork.maa.org/wiki/ConstantsInProblems

and using

Context()->flags->set(
    formatStudentAnswer=>'parsed'
);

Also, if you want students to use names for constants instead of substituting values for those constants, you can set unrealistic values for constants.  For instance, instead of setting a gravity constant to be g = 9.8, you could set g = 2.3618 (some randomly chosen number that students are unlikely to use in their answer).

Best regards,

Paul Pearson