0.0.4 • Published 8 years ago

complex_operation v0.0.4

Weekly downloads
-
License
MIT
Repository
-
Last release
8 years ago

Complex_Operation

Do some basic calculations with Complex numbers #####functions:

  • add
  • substact
  • multiplication
  • divide
  • exponential
  • logarithm
  • negate
  • conjugate
  • angle
  • magnitude
  • equals

Node

You can get this package with NPM:

npm install Complex
var Complex = require('Complex');
console.log(new Complex(3,4).add(Complex(1,1)));    //4+5i

brower

test complex_operation in your brower

require("complex_operation");
var Complex = require("Complex");
var a = new Complex(1,1);
var b = new Complex(2,3);
console.log(a.add(b));

the result is:

Complex 
im:4
real:3

Testing

Testing is done with Complex_test.js

var Complex = require("./Complex");
var c = console;
var c1 = new Complex(1,3), c2= new Complex(2,5);
c.log("c1=%s", c1);
c.log("c2=%s", c2);
c.log("c1 + c2=%s", c1.add(c2));
c.log("c1 - c2=%s", c1.sub(c2));
c.log("c1 * c2=%s", c1.mul(c2));
c.log("c1 / c2=%s", c1.div(c2));
c.log("exp(c1)=%s", c1.exp());
c.log("ln(c1)=%s", c1.ln());
c.log("neg(c1)=%s",c1.neg());
c.log("conj(c1)=%s",c1.conj());
c.log("ang(c1)=%s",c1.ang());
c.log("mag(c1)=%s",c1.mag());
c.log("c1 equ c2 ? ",c1.equ(c2));

API Documentation

Complex Constructor:

var c = new Complex(r,i);
Arguments:

1.r(number) :the real part of the number 2.i(number) :the imaginary part of the number

Method:add

Adds a real or complex number

MyComplex.add(c);
Arguments:

1.c(number,complex)the number to add(MyComplex + c)

Method:sub

Subtracts a real or complex number

MyComplex.sub(c);
Arguments:

1.c(number,complex)the number to subtract(MyComplex - c)

Method:mul

Multiplies the number with a real or complex number

MyComplex.mul(c);
Arguments:

1.c(number,complex)the number to multiply with(MyComplex * c)

Method:div

Divides the number by a real or complex number

MyComplex.div(c);
Arguments:

1.c(number,complex)the number to divide by(MyComplex/c)

Method:exp

Calculates the e^z where the base is E and the exponential the complex number

MyComplex.exp();

Method:ln

Return the natural logarithm(base E)

MyComplex.ln();

Method:neg

Negates the number(multiplies both the real and imaginary part with -1)

MyComplex.neg(c);

####Method:conj Calculates the conjugate of the complex number(multiplies the imaginary part with -1)

MyComplex.conj(c)

####Method:ang Calculates the angle with respect to the real axis,in radians

MyComplex.ang();

####Method:mag Calculates the magnitude of the complex number

MyComplex.mag();

####Method:equ Checks if the real and imaginary components are equal to the passed in complex components

MyComplex.equ(c);
Arguments:

1.c(number,complex)the complex number to compare with

Method:toString

Return a string representation of the complex number

MyComplex.toString();
Examples:
new Complex(2,2).toString();  //2+2i
new Complex(0,7).toString();  //7i
new Complex(7,0).toString();  //7
new Complex(1,5).toString();  //1+5i
'my Complex Number is : ' + (new Complex(3,4));  //'my Complex Number is : 3+4i
0.0.4

8 years ago

0.0.3

8 years ago

0.0.2

8 years ago

0.0.1

8 years ago