Advertisement
Guest User

Untitled

a guest
Oct 25th, 2016
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.51 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace Quiz22015Part3
  8. {
  9. class Program
  10. {
  11. public static Complex FromPolarCoordinates(double magnitude, double phase)
  12. {
  13. Complex polar = new Complex(0, 0);
  14. polar.real = Math.Sqrt(Math.Pow(magnitude, 2) + Math.Pow(phase, 2));
  15. polar.imaginary = (Math.Atan(phase / magnitude)) * 180 / Math.PI;
  16. return polar;
  17. }
  18.  
  19. static void Main(string[] args)
  20. {
  21. Complex comp1 = new Complex(1.0, 2.0);
  22. Complex comp2 = new Complex(1.0, 2.0);
  23.  
  24. Console.WriteLine("Subtraction = " + (comp1 - comp2));
  25. Console.WriteLine("Division = "+ (comp1 / comp2));
  26.  
  27. Console.WriteLine("Rectangular = " + comp1 + " Polar = " + FromPolarCoordinates(1.0,2.0));
  28. }
  29. }
  30. }
  31.  
  32.  
  33.  
  34.  
  35.  
  36.  
  37. using System;
  38. using System.Collections.Generic;
  39. using System.Linq;
  40. using System.Text;
  41. using System.Threading.Tasks;
  42.  
  43. namespace Quiz22015Part3
  44. {
  45. class Complex
  46. {
  47. public double real;
  48. public double imaginary;
  49.  
  50. public Complex(double real, double imaginary)
  51. {
  52. this.real = real;
  53. this.imaginary = imaginary;
  54. }
  55.  
  56. public static Complex operator -(Complex c1, Complex c2)
  57. {
  58. Complex compSub = new Complex(0, 0);
  59. compSub.real = c1.real - c2.real;
  60. compSub.imaginary = c1.imaginary - c2.imaginary;
  61. return compSub;
  62. }
  63.  
  64. public static Complex operator /(Complex c1, Complex c2)
  65. {
  66. Complex compDiv = new Complex(0, 0);
  67. compDiv.real = (((c1.real) * (c2.real)) + ((c1.imaginary) * (c2.imaginary))) / (Math.Pow(c2.real, 2) + Math.Pow(c2.imaginary, 2));
  68. compDiv.imaginary = (((c2.real) * (c1.imaginary)) - ((c1.real) * (c2.imaginary))) / (Math.Pow(c2.real, 2) + Math.Pow(c2.imaginary, 2));
  69. return compDiv;
  70. }
  71.  
  72. public static Complex FromPolarCoordinates(double magnitude, double phase)
  73. {
  74. Complex polar = new Complex(0, 0);
  75. polar.real = Math.Sqrt(Math.Pow(magnitude,2)+Math.Pow(phase,2));
  76. polar.imaginary = (Math.Atan(phase / magnitude)) * 180/Math.PI;
  77. return polar;
  78. }
  79.  
  80. public override string ToString()
  81. {
  82. return string.Format("{0} + {1}i", this.real, this.imaginary);
  83. }
  84. }
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement