Skip to content

Latest commit

 

History

History
108 lines (76 loc) · 2.5 KB

README.md

File metadata and controls

108 lines (76 loc) · 2.5 KB

complex

JSR CI

A package provides implementation of complex numbers and mathematical functions for complex numbers.

What is a complex number?

A complex number is an extension of the real numbers. It combines both real and imaginary components. It can be expressed in form a + bi, where:

  • a: the real part
  • b: the imaginary part
  • i: the imaginary unit

A real number can be regarded as a complex number a + 0i, whose the imaginary part is 0. A purely imaginary number is a complex number 0 + bi, whose the real part is 0.

Complex class

This package provides an implementation of complex numbers through the Complex class. It has methods to perform basic operations on complex numbers:

const cmplx1 = new Complex(3, 1); // 3 + i
const cmplx2 = new Complex(2, 9); // 2 + 9i

cmplx1.add(cmplx2); // (3 + i) + (2 + 9i) = (5 + 10i)

// Also works with real numbers
cmplx1.add(3); // (3 + i) + 3 = (3 + i) + (3 + 0i) = (6 + i)

Methods conj(), abs(), phase() return the conjugate, absolute value, and argument of the complex number respectively:

cmplx2.conj(); // (2 - 9i)
cmplx2.abs(); // ≈ 9.219544457292889 = Math.sqrt(85)
cmplx2.phase(); // 1.3521273809209546

cmplx function

For convenience, the cmplx function was added in v1.1.0 to help create complex numbers more easily.

cmplx(2, 3); // 2 + 3i

Unlike the Complex class, the cmplx function requires the first argument (the real part).

cmplx(0); // 0 + 0i

ComplexMath

Like Math, ComplexMath provides basic mathematics functionality for complex numbers.

  • Exponential and logarithm functions
ComplexMath.exp();
ComplexMath.log();
// ...
  • Hyperbolic functions:
ComplexMath.sinh();
ComplexMath.atanh();
// ...
  • Power functions:
ComplexMath.sqrt();
ComplexMath.pow();
// ...
  • Trigonometric functions:
ComplexMath.asin();
ComplexMath.tan();
// ...

Related

License

MIT