WeBWorK Problems

Simplified radical in complex context

Simplified radical in complex context

by Brittni Lorton -
Number of replies: 2

I am working on a problem where a student needs to simplify various radicals. I would like a student to be given sqrt(-48) and they would need to enter 4sqrt(3)i only, and not sqrt(48)i. 

I may be overthinking this but I am attempting to use both LimitedRadical Context and Complex Context and I cannot seem to get it right. Here is the current code. Any ideas?


DOCUMENT();


loadMacros(

  "PGstandard.pl",

  "MathObjects.pl",

  "PGML.pl",

  "contextFraction.pl",

  "contextLimitedRadical.pl",

  "PGcourse.pl",

  "parserRoot.pl",

  "contextLimitedComplex.pl"

);


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

Context("Numeric");

$a1 = random(2,7,1);

$a2 = random(2,7,1);

$a3 = random(2,7,1);

$nsqa1 = -$a1*$a1;

$nsqa2 = -$a2*$a2;

$m2 = list_random(2,3);

$b = $nsqa2*$m2;

$nsqa3 = -$a3*$a3;

$m3 = list_random(4,5);

$c = $nsqa3*$m3;


Context("LimitedRadical");

$rad2 = Formula("$a2*sqrt($m2)");

$rad3 = Formula("$a3*sqrt($m3)");


Context("Complex");

$ans2 = Complex("$rad2 i");

$ans3 = Complex("$rad3 i");


Context("LimitedComplex-strict");

$ans1 = Complex("$a1 i");


BEGIN_PGML


Simplify the following expressions. 


a. [`\sqrt{[$nsqa1]} = `][_______________]{$ans1}


b. [`\sqrt{[$b]} = `][_______________]{$ans2}


c. [`\sqrt{[$c]} = `][_______________]{$ans3}


END_PGML


In reply to Brittni Lorton

Re: Simplified radical in complex context

by Alex Jordan -

There is also contextLimitedRadicalComplex.pl in the PCC folder of the OPL macros. After loading that, you can have like:

Context("LimitedRadicalComplex");
$ans = Formula("4sqrt(3)i");

Both contextLimitedRadical.pl and contextLimitedRadicalComplex.pl are old, coded mostly by me when I didn't understand what I was doing very well. I don't trust that they are well written, even if they do seem to work. I think they may not give good feedback for certain incorrect answers, for example.

For real answers, I've been using contextFiniteSolutionSets.pl and contextForm.pl, also in the PCC folder of the OPL macros (although my guess is that those versions are not up to date with what we use here). I think these are superior to contextLimitedRadical.pl. But for complex numbers, they are not yet ready and contextLimitedRadicalComplex.pl is my best guess at what to use.

In reply to Alex Jordan

Re: Simplified radical in complex context

by Brittni Lorton -
This worked as I had hoped and was an easy enough fix, thank you for pointing this out!