From WeBWorK

Jump to: navigation


NAME

contextComplexJ.pl - Alters the Complex context to allow the use of j-notation in addition to (or in place of) i-notation for complex numbers.

DESCRIPTION

This macro file adds features to the Complex context that allow both i and j notation for complex numbers. There are flags that control which notation a student must use (a warning is given for the other type), and how complex numbers should be displayed (you can force either form to be used regardless of how they were entered).

USAGE

To use this file, first load it into your problem, then use the Complex context as usual. Both i and j notation will be allowed, and numbers will display in whichever format they were originally entered.

        loadMacros("contextComplexJ.pl");
        
        Context("Complex");
        
        $z1 = Compute("1+3i");
        $z2 = Compute("1+3j");    # equivalent to $z1;
        
        $z1 == $z2;               # true

There are two context flags that control the input and output of complex numbers.

enterComplex => "either" (or "i" or "j")

This specifies what formats the student is allowed to use to enter a complex number. A value of "either" allows either of the formats to be accepted, while the other two options produce error messages if the wrong form is used.

displayComplex => "either" (or "i" or "j")

This controls how complex numbers are displayed. When set to "either", the complex is displayed in whatever format was used to create it. When set to "i" or "j", the display is forced to be in the given format regardless of how it was entered.

By default, the Complex context has both flags set to "either", so the complex numbers remain in the format the student entered them, and either form can be used.

It is possible to set enterComplex and displayComplex to different values. For example.

        Context()->flags->set(
          enterComplex => "either",
          displayComplex => "i",
        );

would allow students to enter complex numbers in either format, but all numebrs would be displayed in standard form.

SETTING THE ALTERNATE FORM AS THE DEFAULT

If you want to force existing problems to allow (or force, or warn about) the j notation, then create a file named parserCustomization.pl in your course's templates/macros directory, and enter the following in it:

        loadMacros("contextComplexJ.pl");
        context::ComplexJ->Default("either","either");

This will alter all the standard Complex contexts to allow students to enter complex numbers in either format, and will display them using the form that was used to enter them.

You could also do

        loadMacros("contextComplexJ.pl");
        context::ComplexJ->Default("i","i");

to cause a warning message to appear when students enter the j format.

If you want to force students to enter the alternate format, use

        loadMacros("contextComplexJ.pl");
        context::ComplexJ->Default("j","j");

This will force the display of all complex numbers to use j notation (so even the ones created in the problem using standard form will show using j's), and will force students to enter their results using j's, though professors answers will still be allowed to be entered in either format (the Default() function converts the first "j" to "either", but arranges that the default flags for the answer checker are set to only allow students to enter complex numbers with j's). This allows you to force j notation in problems without having to rewrite them.