| 1872 | }) |
| 1873 | } |
| 1874 | complex(a=0, b=0) { |
| 1875 | class complex { |
| 1876 | abs() { |
| 1877 | return new BigNumber(this.a).times(this.a).plus(this.b.times(this.b)).sqrt() // sqrt(a^2 + b^2) |
| 1878 | } |
| 1879 | arg() { |
| 1880 | return new BigNumber(this.t.atan2(this.b, this.a)) |
| 1881 | } |
| 1882 | clone() { |
| 1883 | return Object.assign( Object.create( Object.getPrototypeOf(this)), this) |
| 1884 | } |
| 1885 | conjugate() { |
| 1886 | this.b = this.b.negated() |
| 1887 | return this |
| 1888 | } |
| 1889 | constructor(a, b, theoremjs) { |
| 1890 | this.a = new BigNumber(a) |
| 1891 | this.b = new BigNumber(b) |
| 1892 | this.t = theoremjs |
| 1893 | } |
| 1894 | dividedBy() { |
| 1895 | return this.times(...arguments) |
| 1896 | } |
| 1897 | div(complex) { |
| 1898 | if (!complex.isComplex) { |
| 1899 | throw "[TheoremJS]: Complex operation require complex numbers" |
| 1900 | } |
| 1901 | |
| 1902 | const a = this.a |
| 1903 | const b = this.b |
| 1904 | const c = complex.a |
| 1905 | const d = complex.b |
| 1906 | |
| 1907 | const c2d2 = c.times(c).plus(d.times(d)) // c^2 + d^2 |
| 1908 | |
| 1909 | const acbd = a.times(c).plus(b.times(d)) // a*c + b*d |
| 1910 | const bcad = b.times(c).minus(a.times(d)) // b*c - a*d |
| 1911 | |
| 1912 | const re = acbd.div(c2d2) |
| 1913 | const im = bcad.div(c2d2) |
| 1914 | |
| 1915 | this.a = re |
| 1916 | this.b = im |
| 1917 | |
| 1918 | return this |
| 1919 | } |
| 1920 | equal() { |
| 1921 | return this.eq(...arguments) |
| 1922 | } |
| 1923 | eq(complex) { |
| 1924 | if (!complex.isComplex) { |
| 1925 | throw "[TheoremJS]: Complex operation require complex numbers" |
| 1926 | } |
| 1927 | return this.a.eq(complex.a) && this.b.eq(complex.b) |
| 1928 | } |
| 1929 | exp() { |
| 1930 | const a = this.a |
| 1931 | const b = this.b |