.NET 4.0 New Feature - Complex
Sub Main()
ShowDetail("Complex.Zero", Complex.Zero)
ShowDetail("Complex.One", Complex.One)
Dim c1 As New Complex(1, 2)
Dim c2 As New Complex(3, 4)
ShowDetail("C1", c1)
ShowDetail("C2", c2)
'Complex +-*/
Console.WriteLine("{0} + {1} = {2}", c1, c2, c1 + c2)
Console.WriteLine("{0} - {1} = {2}", c1, c2, c1 - c2)
Console.WriteLine("{0} * {1} = {2}", c1, c2, c1 * c2)
Console.WriteLine("{0} / {1} = {2}", c1, c2, c1 / c2)
Console.WriteLine()
Console.WriteLine("Complex.Add({0}, {1}) = {2}", c1, c2, Complex.Add(c1, c2))
Console.WriteLine("Complex.Subtract({0}, {1}) = {2}", c1, c2, Complex.Subtract(c1, c2))
Console.WriteLine("Complex.Multiply({0}, {1}) = {2}", c1, c2, Complex.Multiply(c1, c2))
Console.WriteLine("Complex.Divide({0}, {1}) = {2}", c1, c2, Complex.Divide(c1, c2))
Console.WriteLine()
'Other Complex operation
Console.WriteLine("Complex.Divide({0}) = {1}", c1, Complex.Conjugate(c1))
Console.WriteLine("Complex.Abs({0}) = {1}", c1, Complex.Abs(c1))
Console.WriteLine("Complex.Negate({0}) = {1}", c1, Complex.Negate(c1))
Console.WriteLine("Complex.Pow({0}, 2) = {1}", c1, Complex.Pow(c1, 2))
Console.WriteLine("Complex.Pow({0}, {1}) = {2}", c1, c2, Complex.Pow(c1, c2))
Console.WriteLine("Complex.Sqrt({0}) = {1}", c1, Complex.Sqrt(c1))
Console.WriteLine("Complex.Reciprocal({0}) = {1}", c1, Complex.Reciprocal(c1))
Console.WriteLine("Complex.Log({0}) = {1}", c1, Complex.Log(c1))
Console.WriteLine("Complex.Log10({0}) = {1}", c1, Complex.Log10(c1))
Console.WriteLine("Complex.exp({0}) = {1}", c1, Complex.Exp(c1))
Console.WriteLine()
Console.WriteLine("Complex.Sin({0}) = {1}", c1, Complex.Sin(c1))
Console.WriteLine("Complex.Sinh({0}) = {1}", c1, Complex.Sinh(c1))
Console.WriteLine("Complex.Cos({0}) = {1}", c1, Complex.Cos(c1))
Console.WriteLine("Complex.Cosh({0}) = {1}", c1, Complex.Cosh(c1))
Console.WriteLine("Complex.Tan({0}) = {1}", c1, Complex.Tan(c1))
Console.WriteLine("Complex.Tanh({0}) = {1}", c1, Complex.Tanh(c1))
Console.WriteLine("Complex.Asin({0}) = {1}", c1, Complex.Asin(c1))
Console.WriteLine("Complex.Acos({0}) = {1}", c1, Complex.Acos(c1))
Console.WriteLine("Complex.Atan({0}) = {1}", c1, Complex.Atan(c1))
End Sub
Private Sub ShowDetail(ByVal varName As String, ByVal c As Complex)
Console.WriteLine("{0}: {1}", varName, c)
ShowDetail(c)
Console.WriteLine()
End Sub
Private Sub ShowDetail(ByVal c As Complex)
Console.WriteLine("Real: {0}", c.Real)
Console.WriteLine("Imaginary: {0}", c.Imaginary)
Console.WriteLine("Phase: {0}", c.Phase)
Console.WriteLine("Magnitude: {0}", c.Magnitude)
End Sub
End Module
Complex.One: (1, 0) Real: 1 Imaginary: 0 Phase: 0 Magnitude: 1
C1: (1, 2) Real: 1 Imaginary: 2 Phase: 1.10714871779409 Magnitude: 2.23606797749979
C2: (3, 4) Real: 3 Imaginary: 4 Phase: 0.927295218001612 Magnitude: 5
(1, 2) + (3, 4) = (4, 6) (1, 2) - (3, 4) = (-2, -2) (1, 2) * (3, 4) = (-5, 10) (1, 2) / (3, 4) = (0.44, 0.08)
Complex.Add((1, 2), (3, 4)) = (4, 6) Complex.Subtract((1, 2), (3, 4)) = (-2, -2) Complex.Multiply((1, 2), (3, 4)) = (-5, 10) Complex.Divide((1, 2), (3, 4)) = (0.44, 0.08)
Complex.Divide((1, 2)) = (1, -2) Complex.Abs((1, 2)) = 2.23606797749979 Complex.Negate((1, 2)) = (-1, -2) Complex.Pow((1, 2), 2) = (-3, 4) Complex.Pow((1, 2), (3, 4)) = (0.129009594074467, 0.0339240929051702) Complex.Sqrt((1, 2)) = (1.27201964951407, 0.786151377757423) Complex.Reciprocal((1, 2)) = (0.2, -0.4) Complex.Log((1, 2)) = (0.80471895621705, 1.10714871779409) Complex.Log10((1, 2)) = (0.349485002168008, 0.480828578784232) Complex.exp((1, 2)) = (-1.13120438375681, 2.47172667200482)
Complex.Sin((1, 2)) = (3.16577851321617, 1.95960104142161) Complex.Sinh((1, 2)) = (-0.489056259041294, 1.40311925062204) Complex.Cos((1, 2)) = (2.03272300701967, -3.0518977991518) Complex.Cosh((1, 2)) = (-0.64214812471552, 1.06860742138278) Complex.Tan((1, 2)) = (0.0338128260798967, 1.01479361614663) Complex.Tanh((1, 2)) = (1.16673625724092, -0.243458201185725) Complex.Asin((1, 2)) = (0.427078586392476, 1.528570919481) Complex.Acos((1, 2)) = (1.14371774040242, -1.528570919481) Complex.Atan((1, 2)) = (1.33897252229449, 0.402359478108525)