WeBWorK Problems

Fractions-NoDecimals for Matrices

Fractions-NoDecimals for Matrices

by Brittni Lorton -
Number of replies: 2

I have having a strange issue pop up in the below problem. I want to ensure students only enter fractions, and not decimals. The code here seems to be working, but when a student enters the decimal value for the [1,1] entry and the fraction value for the other entries, they just get 'incorrect' and not the message saying they need to use fractions. When a student enters the decimal in the [2,2] entry they get the desired message of 'in entry (2,2): You are only allowed to enter fractions, not decimals." Weird! Any insight as to why this is and if there is a fix?



DOCUMENT();



loadMacros(

"PGstandard.pl",

"MathObjects.pl",

"PGchoicemacros.pl",

"PGmatrixmacros.pl",

"parserAssignment.pl",

"PGML.pl",

"MatrixReduce.pl",

"PGcourse.pl",

);


TEXT(beginproblem());

##########################

#  Setup


Context('Fraction-NoDecimals');

Context()->parens->set("[" => {formMatrix => 1});



do {

$a = random(-1,1,2) * random(2,9,1);

$d = random(-1,1,2) * random(2,9,1);

$b = 0;

$c = 0;

} until ($a != $d);


$A = Matrix([[$a, $b], [$c, $d]]);

$A = apply_fraction_to_matrix_entries($A);


$Ainv = $A->inverse;

$Ainv = apply_fraction_to_matrix_entries($Ainv);


Context()->texStrings;

BEGIN_TEXT


If \( A = $A, \)

$BR

then 

$BR

\( A^{-1} = \) \{ $Ainv->ans_array(7) \}.  

$BR

Enter elements as fractions, not decimals.

END_TEXT


Context()->normalStrings;


ANS($Ainv->cmp);


COMMENT();


ENDDOCUMENT();

In reply to Brittni Lorton

Re: Fractions-NoDecimals for Matrices

by Brittni Lorton -

Here is a screenshot of what we are seeing here. 




Attachment Capture.PNG
In reply to Brittni Lorton

Re: Fractions-NoDecimals for Matrices

by Christopher Heckman -
I'm not sure whether this got resolved, but I checked some things out.

The default format for a student's answer is a Formula MathObject, not a Fraction MathObject. Hence, WeBWorK gets 0.2, not 1/5, in the standard answer checker. So the ultimate issue is the parser that interprets the student's answer, and the answer is as simple (and as complicated) as finding the proper parameter and what its value should be.

In 2014, Paul Pearson mentioned something along similar lines:

During our workshop session this morning, one question in the chat window was about how to 

(1) display a reduced fraction in the text of a webwork question and 

(2) require that students enter their answer as a reduced fraction.
 
This would probably give you a solution that is quicker to implement.