Click here to Skip to main content
15,895,813 members
Articles / Programming Languages / Visual Basic

Complex Math Library for C# and VB.NET

Rate me:
Please Sign up or sign in to vote.
3.94/5 (17 votes)
15 Dec 2002CPOL9 min read 256.2K   3.6K   39  
Complex math library for C# and VB.NET
Imports System.Collections

Imports KarlsTools

Module Module1

    Sub Main()
        sub2()
    End Sub

    Sub sub2()
        Dim c1 As Complex = New Complex(3, 4)

        Dim s As String = "c1 =  " + c1.ToString()
        Dim d As Double = Complex.Abs(c1)
        Dim d2 As Double = Complex.Arg(c1)
        Dim c2 As Complex = Complex.Conj(c1)
        Dim imag As Double = Complex.Imag(c2)
        Dim real As Double = Complex.Real(c1)
        Dim imag2 As Double = c1.Imag()
        Dim real2 As Double = c1.Real()
        Dim p As Complex = Complex.Polar(5, Math.PI / 180)
        Dim c3 As Complex = Complex.Cos(p)
        Dim c4 As Complex = Complex.Cosh(p)
        Dim c5 As Complex = Complex.Exp(p)
        Dim c6 As Complex = Complex.Log(p)
        Dim c7 As Complex = Complex.Log10(p)
        Dim n As Double = Complex.Norm(p)
        Dim c9 As Complex = Complex.Pow(p, 4)
        Dim c10 As Complex = Complex.Pow(p, p)
        Dim c11 As Complex = Complex.Pow(2, p)
        Dim c12 As Complex = Complex.Sin(p)
        Dim c13 As Complex = Complex.Sinh(p)
        Dim c14 As Complex = Complex.Sqrt(p)
        Dim c15 As Complex = Complex.Tan(p)
        Dim c15a As Complex = Complex.Tanh(p)

        Dim c16 As Complex = Complex.Negative(c15)
        Dim c17 As Complex = Complex.Plus(c16)
        Dim eq As Boolean = c16.Equals(c17)
        Dim eq2 As Boolean = (New Complex(2, 0)).Equals(2)
        Dim eq3 As Boolean = Complex.Equals(2, New Complex(2, 0))
        Dim ne As Boolean = Complex.NotEqual(c16, c16)
        Dim ne2 As Boolean = Complex.NotEqual(New Complex(2, 0), 2)
        Dim ne3 As Boolean = Complex.NotEqual(2, New Complex(2, 0))
        Dim c18 As Complex = Complex.Multiply(c1, c1)
        Dim c19 As Complex = Complex.Multiply(c1, Double.PositiveInfinity)
        Dim c20 As Complex = Complex.Multiply(12, c1)
        Dim c21 As Complex = Complex.Divide(c1, c1)
        Dim c22 As Complex = Complex.Divide(c1, Double.PositiveInfinity)
        Dim c23 As Complex = Complex.Divide(1, c1)
        Dim c24 As Complex = Complex.Add(c1, c1)
        Dim c25 As Complex = Complex.Add(c1, Double.PositiveInfinity)
        Dim c26 As Complex = Complex.Add(1, c1)
        Dim c27 As Complex = Complex.Subtract(c1, c1)
        Dim c28 As Complex = Complex.Subtract(c1, Double.PositiveInfinity)
        Dim c29 As Complex = Complex.Subtract(1, c1)

        Console.WriteLine("c1 = " & c1.ToString())
        Console.WriteLine("s = " & s)
        Console.WriteLine("d = " & d)
        Console.WriteLine("d2 = " & d2)
        Console.WriteLine("c2 = " & c2.ToString())
        Console.WriteLine("imag = " & imag)
        Console.WriteLine("real = " & real)
        Console.WriteLine("imag2 = " & imag2)
        Console.WriteLine("real2 = " & real2)
        Console.WriteLine("p = " & p.ToString())
        Console.WriteLine("c3 = " & c3.ToString())
        Console.WriteLine("c4 = " & c4.ToString())
        Console.WriteLine("c5 = " & c5.ToString())
        Console.WriteLine("c6 = " & c6.ToString())
        Console.WriteLine("c7 = " & c7.ToString())
        Console.WriteLine("n = " & n)
        Console.WriteLine("c9 = " & c9.ToString())
        Console.WriteLine("c10 = " & c10.ToString())
        Console.WriteLine("c11 = " & c11.ToString())
        Console.WriteLine("c12 = " & c12.ToString())
        Console.WriteLine("c13 = " & c13.ToString())
        Console.WriteLine("c14 = " & c14.ToString())
        Console.WriteLine("c15 = " & c15.ToString())
        Console.WriteLine("c15a = " & c15a.ToString())
        Console.WriteLine("c16 = " & c16.ToString())
        Console.WriteLine("c17 = " & c17.ToString())
        Console.WriteLine("eq = " & eq)
        Console.WriteLine("eq2 = " & eq2)
        Console.WriteLine("eq3 = " & eq3)
        Console.WriteLine("ne = " & ne)
        Console.WriteLine("ne2 = " & ne2)
        Console.WriteLine("ne3 = " & ne3)
        Console.WriteLine("c18 = " & c18.ToString())
        Console.WriteLine("c19 = " & c19.ToString())
        Console.WriteLine("c20 = " & c20.ToString())
        Console.WriteLine("c21 = " & c21.ToString())
        Console.WriteLine("c22 = " & c22.ToString())
        Console.WriteLine("c23 = " & c23.ToString())
        Console.WriteLine("c24 = " & c24.ToString())
        Console.WriteLine("c25 = " & c25.ToString())
        Console.WriteLine("c26 = " & c26.ToString())
        Console.WriteLine("c27 = " & c27.ToString())
        Console.WriteLine("c28 = " & c28.ToString())
        Console.WriteLine("c29 = " & c29.ToString())
    End Sub
End Module

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Other
United States United States
Karl is a Water Resources Engineer and Programmer. He holds a Masters degree in Civil Engineering, and is a Microsoft Certified Solution Developer.

Comments and Discussions