Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace Quiz22015Part3
- {
- class Program
- {
- public static Complex FromPolarCoordinates(double magnitude, double phase)
- {
- Complex polar = new Complex(0, 0);
- polar.real = Math.Sqrt(Math.Pow(magnitude, 2) + Math.Pow(phase, 2));
- polar.imaginary = (Math.Atan(phase / magnitude)) * 180 / Math.PI;
- return polar;
- }
- static void Main(string[] args)
- {
- Complex comp1 = new Complex(1.0, 2.0);
- Complex comp2 = new Complex(1.0, 2.0);
- Console.WriteLine("Subtraction = " + (comp1 - comp2));
- Console.WriteLine("Division = "+ (comp1 / comp2));
- Console.WriteLine("Rectangular = " + comp1 + " Polar = " + FromPolarCoordinates(1.0,2.0));
- }
- }
- }
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace Quiz22015Part3
- {
- class Complex
- {
- public double real;
- public double imaginary;
- public Complex(double real, double imaginary)
- {
- this.real = real;
- this.imaginary = imaginary;
- }
- public static Complex operator -(Complex c1, Complex c2)
- {
- Complex compSub = new Complex(0, 0);
- compSub.real = c1.real - c2.real;
- compSub.imaginary = c1.imaginary - c2.imaginary;
- return compSub;
- }
- public static Complex operator /(Complex c1, Complex c2)
- {
- Complex compDiv = new Complex(0, 0);
- compDiv.real = (((c1.real) * (c2.real)) + ((c1.imaginary) * (c2.imaginary))) / (Math.Pow(c2.real, 2) + Math.Pow(c2.imaginary, 2));
- compDiv.imaginary = (((c2.real) * (c1.imaginary)) - ((c1.real) * (c2.imaginary))) / (Math.Pow(c2.real, 2) + Math.Pow(c2.imaginary, 2));
- return compDiv;
- }
- public static Complex FromPolarCoordinates(double magnitude, double phase)
- {
- Complex polar = new Complex(0, 0);
- polar.real = Math.Sqrt(Math.Pow(magnitude,2)+Math.Pow(phase,2));
- polar.imaginary = (Math.Atan(phase / magnitude)) * 180/Math.PI;
- return polar;
- }
- public override string ToString()
- {
- return string.Format("{0} + {1}i", this.real, this.imaginary);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement