Just include the file Complex.js into your page or require it in your ssjs script.
Build via Packager, requires MooTools Core to be registered to Packager already (ty cpojer)
./packager register /path/to/Complex ./packager build Complex/* > Complex
var z = new Complex(real[, im]);
var z = new Complex(2, 4); var z = new Complex('2+5i');
A in line function like Number.from.
var z = Complex.from(real, im);
The same as the Complex constructor.
Creates a complex instance from a polar representation: r*e^(phi*i) = r (cos(phi) + i sin(phi))
var z = Complex.fromPolar(r, phi);
A instance of the imaginary unit i
var i = Complex.i;
A instance for the real number 1
var one = Complex.one;
Sets the real and imaginary properties a and b from a + bi
Sets the a and b in a + bi from a polar representation.
Sets the precision of the numbers. Similar to Number.prototype.toPrecision. Useful befor printing the number with the toString method.
Formats a number using fixed-point notation. Similar to Number.prototype.toFixed. Useful before printing the number with the toString method.
Finalizes the instance. The number will not change and any other method call will return a new instance. Very useful when a complex instance should stay constant. For example the Complex.i variable is a finalized instance.
Calculates the magnitude of the complex number
Calculates the angle with the real axis.
Calculates the conjungate of the complex number (multiplies the imaginary part with -1)
Negates the number (multiplies both the real and imaginary part with -1)
Multiplies the number with a real or complex number
Devides the number by a real or complex number
Adds a real or complex number
Subtracts a real or complex number
Returns the base to the exponent
Returns the square root
Returns the natural logarithm (base E)
Calculates the e^z where the base is E and the exponential the complex number.
Calculates the sine of the complex number
Calculates the cosine of the complex number
Calculates the tangent of the complex number
Calculates the hyperbolic sine of the complex number
Calculates the hyperbolic cosine of the complex number
Calculates the hyperbolic tangent of the complex number
Returns a new Complex instance with the same real and imaginary properties
Returns a string representation of the complex number
new Complex(1, 2).toString(); // 1+2i new Complex(0, 1).toString(); // i new Complex(4, 0).toString(); // 4 new Complex(1, 1).toString(); // 1+i 'my Complex Number is: ' + (new Complex(3, 5)); // 'my Complex Number is: 3+5i
Checks if the real and imaginary components are equal to the passed in compelex components.
new Complex(1, 4).equals(new Complex(1, 4)); // true new Complex(1, 3).equals(new Complex(1, 3)); // false
Each method of the Complex object is added to the Number object, so it is easy to use them together.
(3).add(new Complex(2, 4)).toString(); // 5+4i
Returns a Complex instance where the real component is the value of the number.
(3).toComplex().add(new Complex(3, 4)).toString(); // 6+4i
Number.from accepts Complex instances. It will return the real component.
Number.from(new Complex(3, 4)); // 3
The following functions are added to the Math object:
String implements the following methods:
Parses a string like 3+5i into a Complex instance.
'4+2i'.toComplex(); // a complex instance with the real component = 4 and the imaginary component = 2
A note on comments here: These comments are moderated. No comments will show up until they are approved. Comments that are not productive (i.e. inflammatory, rude, etc) will not be approved.
Found a bug in this plugin? Please report it this repository's Github Issues.blog comments powered by Disqus