Difference between revisions of "Complex (MathObject Class)"

From WeBWorK_wiki
Jump to navigation Jump to search
(Created page)
 
Line 1: Line 1:
 
== The Complex Class ==
 
== The Complex Class ==
   
: The Complex class implements complex numbers with "fuzzy" comparison (due to the fact that the real and complex parts are handled using MathObject Reals). As with Real objects, you can add, subtract, multiply, and perform the other usual arithmetic operations on Complex objects, and can compute <code>sin()</code>, <code>sqrt()</code> and the other standard functions on Complex arguments. In addition, there are <code>arg()</code> and <code>mod()</code>, which return the argument or modulus of a Complex value, and <code>Re()</code> and <code>Im()</code> that return its real or imaginary part. The <code>conj()</code> function returns the complex conjugate of a Complex object. The value <code>i</code> represents <math>\sqrt{-1}</math> and can be used in your Perl expressions to produce complex numbers. Note that you must use <code>-(i)</code> to obtain <math>-i</math> in Perl expressions (but not in strings parsed by MathObjects, such as student answers or the arguments to <code>Compute()</code>).
+
The Complex class implements complex numbers with "fuzzy" comparison (due to the fact that the real and complex parts are handled using MathObject Reals). As with Real objects, you can add, subtract, multiply, and perform the other usual arithmetic operations on Complex objects, and can compute <code>sin()</code>, <code>sqrt()</code> and the other standard functions on Complex arguments. In addition, there are <code>arg()</code> and <code>mod()</code>, which return the argument or modulus of a Complex value, and <code>Re()</code> and <code>Im()</code> that return its real or imaginary part. The <code>conj()</code> function returns the complex conjugate of a Complex object. The value <code>i</code> represents <math>\sqrt{-1}</math> and can be used in your Perl expressions to produce complex numbers. Note that you must use <code>-(i)</code> to obtain <math>-i</math> in Perl expressions (but not in strings parsed by MathObjects, such as student answers or the arguments to <code>Compute()</code>).
   
 
Context("Complex");
 
Context("Complex");
Line 17: Line 17:
 
$w = $z - (i); # parens needed in Perl expressions
 
$w = $z - (i); # parens needed in Perl expressions
   
  +
<br>
   
 
[[Category:MathObject_Classes]]
 
[[Category:MathObject_Classes]]

Revision as of 16:34, 2 August 2012

The Complex Class

The Complex class implements complex numbers with "fuzzy" comparison (due to the fact that the real and complex parts are handled using MathObject Reals). As with Real objects, you can add, subtract, multiply, and perform the other usual arithmetic operations on Complex objects, and can compute sin(), sqrt() and the other standard functions on Complex arguments. In addition, there are arg() and mod(), which return the argument or modulus of a Complex value, and Re() and Im() that return its real or imaginary part. The conj() function returns the complex conjugate of a Complex object. The value i represents [math]\sqrt{-1}[/math] and can be used in your Perl expressions to produce complex numbers. Note that you must use -(i) to obtain [math]-i[/math] in Perl expressions (but not in strings parsed by MathObjects, such as student answers or the arguments to Compute()).

   Context("Complex");
   
   $z = Complex(2,3);
   $z = Complex([2,3]);
   $z = 2 + 3 * i;
   $z = Complex("2 + 3i");
   $z = Compute("2 + 3i");
   
   $w = sin($z);      # same as Compute("sin(2+3i)");
   $w = conj($z);     # same as Complex("2 - 3i");
   $w = $z**2;        # same as Compute("(2+3i)^2");
   $w = $z + 5*i;     # same as Complex("2 + 8i");
   $w = $z - (i);     # parens needed in Perl expressions