New to Nutbox?

Complex information

1 comment

drago18121996
68
7 days agoSteemit

export class ComplexNumber {
r : number;
i : number;

constructor(real: number, imaginary: number) {
this.r = real;
this.i = imaginary;
}

public get real(): number {
return this.r;
}

public get imag(): number {
return this.i;
}

public add(other: ComplexNumber): ComplexNumber {
return new ComplexNumber((this.r+other.r),(this.i+other.i));
}

public sub(other: ComplexNumber): ComplexNumber {
return new ComplexNumber((this.r-other.r),(this.i-other.i));
}

public mul(other: ComplexNumber): ComplexNumber {
return new ComplexNumber((this.rother.r-this.iother.i),(this.iother.r+this.rother.i));
}

public div(other: ComplexNumber): ComplexNumber {
return new ComplexNumber((this.rother.r+this.iother.i)/(other.rother.r+other.iother.i),(this.iother.r-this.rother.i)/(other.rother.r+other.iother.i));
}

public get abs(): number {
return Math.sqrt(this.ithis.i+this.rthis.r);
}

public get conj(): ComplexNumber {
return new ComplexNumber(this.real, this.imag ? this.imag * (-1) : 0);
}

public get exp(): ComplexNumber {
return new ComplexNumber(Math.exp(this.r)Math.cos(this.i), Math.exp(this.r)Math.sin(this.i));
}
}

Comments

Sort byBest