contextComplexJ.pl
that makes this change. See the comments in the file for more details. It gives a way to write a problem that has a variable that you can switch to make it work with either notation.
In any case, I have rewritten the contextComplexJ.pl
so that it can be used from PGcourse.pl
to set the default that you would like for your course without having to modify the problems. (Along the lines of the contextAlternateIntervals.pl
and contextAlternateDecimal.pl
that I posted last week).
You can now control the way complex number are input and displayed separately, and can force student input to be in j notation without requiring that the problem be written using j notation.
The file is attached, and the documentation is given below. See in particular the section on setting the complex j as the default at the end. Hope that does the trick.
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; # trueThere 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 namedparserCustomization.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.
joel_test
directory, so the problems in that directory will load the new one in preference to the one in pg/macros
, and the problem now works for me as expected.
pg/macros
(where the location of pg
depends on your installation, but typically is /opt/pg
). There are also macro directories in the Problem Library, and you can consider those as system provided.File you you provide (or that you want to use to override the system ones) go in your course's
templates/macros
folder. This makes those macros available on a course-wide basis, so they will be used by all problems that call on them that you assign to homework sets within your course. but no one else's courses will use them.My expectation was that you would put the
contextComplexJ.pl
file in your course templates/macros
directory to be used that way.The other place you can put macro files is in the directory containing the PG files that use them. This is how the Workshop2 slides that I made work (the
templates/local/setWorkshops2
directory contains all the custom macro files that are needed by the slides). So when I said I put the contextComplexJ.pl
file in your directory, I means in the templates/local/joel_test
directory in the PREP2014 course. That way your PG files in that directory would get the new contextComplexJ.pl
file without my interfering with anyone else's use of contextComplexJ.pl
in the PREP2014 course.If you are doing your development on your own server, you will need to move the
contextComplexJ.pl
to your server and install it in one of the places that I mentioned above. You can use the File Manager (link in the sidebar) to do that. It will let you navigate to your course's templates/macros
folder where you can use the "Upload" button below the file list to upload the macro file to your course. We did discuss that sort of thing briefly on the first day of the course, but it may have been too soon for you to realize the implications of it.
contextComplex.pl
file to load MathObjects.pl
itself. It didn't occur to me that the order would matter when I wrote it. That's what you testers are for! :-)
loadMacros(
"contextComplexJ.pl",
);
Context("Complex");
# modified to use j for i = sqrt(-1)
Context()->flags->set(
enterComplex => "either", # input either i or j
displayComplex => "j", # display only j
);
is run during the loadMacros operation.
Since part of the code is Context("Complex"); then I should not use
that in the *.pg code that defines my problem - right? So I have to "know"
that my PGcourse.pl sets the context to Complex. This maybe fine since most
of what we do is complex, but you have mentioned that I was declaring
complex in problems that didn't need it. What is the downside to living in the context Complex?
I give the documentation for contextComplexJ.pl
above, and you should look at the section called "SETTING THE ALTERNATE FORM AS THE DEFAULT". That tells you what you need to add to PGcourse.pl
. (That section actually suggests using a different file, parserCustomization.pl
, which is loaded whenever MathObjects.pl
is loaded. So does not rely on PGcourse.pl
, which is not included in all PG files.)
So I'd follow the examples in the documentation and use
loadMacros("contextComplexJ.pl"); context::ComplexJ->Default("j","j");to force students to enter numbers using j-notion and print all results using j-notation (see the note at the end of the documentation above), or
loadMacros("contextComplexJ.pl"); context::ComplexJ->Default("either","j");to allow students to enter either format, but show results using j-notation.