WeBWorK Problems

FormulaWithUnits in a List problem

FormulaWithUnits in a List problem

by Ian Delbridge -
Number of replies: 0
I'm working on a problem where I want the answer to be a a formula with units. It's pretty simple: given a quadratic, use the quadratic formula to solve for when time t is zero. Everything seems to work, but when I put it in a List, it doesn't seem to stay a formula with units. It drops off the units. 

So when I try it out and check solutions, it gives me just a formula with no units, and gives the error message Variable 's' is not defined in this context. 

It keeps the units fine without the List, though. Is this a bug? I figure FormulaWithUnits probably isn't used too often so it's more likely for a bug here than in more commonly used parts of MathObjects. 

Another thing is that I'm not sure why, but this is what I get as the answer: 
[6+sqrt(-36-4*g*9)]/(2*g), [6-sqrt(-36-4*g*9)]/(2*g)

I squared the (-6), so I should have +36, not -36.

With Gratitude,
Ian Delbridge


Context()->variables->add( t => 'Real',
                           g => 'Real');
$a = Formula("g");
$b = Compute(list_random(-2,-4,-6));
$c = Compute(list_random(3,6,9));

$v = ($b);
$x = ($c);

$quad1 = FormulaWithUnits("(-$b+sqrt($b^2-4*$a*$c))/(2*$a)","s");
$quad2 = FormulaWithUnits("(-$b-sqrt($b^2-4*$a*$c))/(2*$a)","s");

$factors = List($quad1,$quad2);