// Calculate the distance between two complex numbers public static double getDisBtwTwoComplexNrs(ComplexNr complexNr1, ComplexNr complexNr2) { ComplexNr difference = complexNr2 - complexNr1; return(roundNr( Math.Sqrt(Math.Pow(difference.realPart, 2) + Math.Pow(difference.imaginaryPart, 2)) )); }
public virtual ComplexNr toThePower(int power) { ComplexNr result = this; for (int i = 0; i < power - 1; i++) { result *= this; } return(result); }
// Get the numbers of the trigonometric form public Program.trigonometricForm getNrsOfTrigoForm(ComplexNr complexNr, int power) { double theta = Math.Atan(this.imaginaryPart / this.realPart); double r = Math.Sqrt(Math.Pow(this.realPart, 2) + Math.Pow(this.imaginaryPart, 2)); return(new Program.trigonometricForm { factor = roundNr(Math.Pow(r, power)), realPart = Math.Cos(theta * power), imaginaryPart = Math.Sin(theta * power) }); }
static void Main(string[] args) { try { ComplexNr complexNr1 = new ComplexNr(); ComplexNr complexNr2 = new ComplexNr(2, -3); int realNr = 3; Console.WriteLine($"{complexNr1} + {complexNr2} = {complexNr1 + complexNr2}"); Console.WriteLine($"{complexNr1} - {complexNr2} = {complexNr1 - complexNr2}"); Console.WriteLine($"{complexNr1} * {complexNr2} = {complexNr1 * complexNr2}"); Console.WriteLine($"{complexNr1} ^ {realNr} = {complexNr1.toThePower(realNr)}"); Console.WriteLine($"The trigonometric form: " + $"{complexNr1.trigonometricFormToThePowerOf()}"); Console.WriteLine($"The trigonometric form to the power of {realNr}: " + $"{complexNr1.trigonometricFormToThePowerOf(realNr)}"); Console.WriteLine(); ComplexD complexD = new ComplexD(); ComplexNr[] listOfComplexNrs = new ComplexNr[5] { new ComplexNr(14, 6), new ComplexNr(-12, 0), new ComplexNr(3, 9), new ComplexNr(5, 5), new ComplexNr(7, 12), }; Console.WriteLine($"{complexD} ^ {realNr} (calculated with the trigonometric" + $" form) = {complexD.toThePower(realNr)}"); Console.WriteLine($"The distance between the complex number and a set of complex" + $" numbers is {complexD.getDisBtwCompAndSet(listOfComplexNrs)}"); } catch (ArgumentException error) { Console.WriteLine(error.Message); } }