Category:MathObject Classes

From WeBWorK
Jump to: navigation, search

MathObject Classes

The MathObjects library defines a number of object classes for various mathematical concepts, such as real numbers, complex numbers, intervals, vectors, points, and so on. To use these objects in a problem you are writing, include MathObjects.pl in your loadMacros() call. For example:

   loadMacros(
     "PGstandard.pl",
     "MathObjects.pl",
     "PGcourse.pl",
   );

Once this is done, there are several ways to create MathObjects in your problem:

  • By calling a constructor function for the type of object you want (e.g., Real(3.5) or Complex("3+4i"))
  • By calling Compute() to parse a string and return the resulting object (e.g., Compute("3+4i"))
  • By calling a method of an existing MathObject that returns another object (e.g., Formula("sin(x)")->eval(x => pi/2))
  • By combining existing MathObjects via mathematical operations (e.g., $x = Formula("x"); $f = $x**2 + 2*$x + 1)

The links in the next section include examples of how to create and use each MathObject class.


The Main MathObject Classes

The following links describe the various classes in more detail:

  • Real -- implements real numbers
  • Infinity -- implements infinity and negative infinity
  • Complex -- implements complex numbers
  • Point -- implements points in \({\bf R}^n\) and \({\bf C}^n\)
  • Vector -- implements vectors in \({\bf R}^n\) and \({\bf C}^n\)
  • Matrix -- implements matrices over the real and complex numbers
  • List -- implements lists of arbitrary MathObjects
  • Interval -- implements intervals of real numbers
  • Set -- implements finite sets of real numbers
  • Union -- implements unions of intervals or sets
  • String -- implements special words like NONE and DNE
  • Formula -- implements expressions involving one or more variables


Other Classes

The pg/macros directory contains a number of extensions to MathObjects, including files that define specialized MathObject types. The ones that begin with parser typically define a new object class. For example, parserParametricLine.pl defines a constructor ParametricLine() for creating a special object that checks if a student's answer is a given parametric line or not, even if it is parameterized differently. These files usually contain documentation within them; see the POD documentation for versions that you can read on line.


follow us