Results 1 to 5 of 5

Thread: Complex Numbers

  1. #1

    Thread Starter
    New Member
    Join Date
    Sep 2000
    Posts
    3

    Question

    Does anyone know how to use complex numbers in visual basic? Or if it is possible to use them at all??

    ie. What keyword do you use to signify i - the imaginary part?

    Help would be greatly appreciated

    Goat_Man

  2. #2
    Fanatic Member
    Join Date
    Aug 2000
    Posts
    617

    doubt it! but

    Doubt it!

    But tell me what you have in mind to do with complex numbers
    (if you don't mind)

  3. #3

    Thread Starter
    New Member
    Join Date
    Sep 2000
    Posts
    3

    Complex Numbers

    To Lafor

    I just wrote a simple program to draw a mandelbrot set and am just requiring the use of complex numbers to finish it. Unfortunetly the Mandelbrot set isnt going to work without the use of complex numbers! Oh well...

    I thought VB would have utilised them seeing as they arent exactly ultra hardcore mathmatics or anything. But anyway...

  4. #4
    Frenzied Member
    Join Date
    Jul 1999
    Location
    Huntingdon Valley, PA 19006
    Posts
    1,151

    Program complex arithmetic

    You can program complex arithmetic. I suggest Functions for +, -, *, & / used with a Type defined as complex. Something like the following.
    Code:
    Public Type Complex
        X As Double
        Y As Double
      End Type
    
    Public Function Cproduct(A As Complex, B As Complex) _
                                As Complex
    Dim Result As Complex
    
    Result.X = A.X * B.X - A.Y * B.Y
    Result.Y = A.X * B.Y + A.Y * B.X
    Cproduct = Result
    
    End Function
    Public Function Csum(A As Complex, B As Complex) _
                                As Complex
    Dim Result As Complex
    
    Result.X = A.X + B.X
    Result.Y = A.Y + B.Y
    Csum = Result
    
    End Function
    Public Function Cquotient(A As Complex, B As Complex) _
                                As Complex
    Dim Result As Complex
    Dim R As Double
    
    R = B.X * B.X + B.Y * B.Y
    
    
    Result.X = (A.X * B.X + A.Y * B.Y) / R
    Result.Y = (A.Y * B.X - A.X * B.Y) / R
    Cquotient = Result
    
    End Function
    Use the above Functions as required to do your complex arithmetic. To avoid repetitive stress syndrome, you might want to use shorter names for the functions.

    I did just a little checking of these functions, and am about 95% sure they are correct. It has been a lot of years since I did complex arithmetic, so perhaps you should verify my algebra.

    Give me brief progress report when you get your project done.
    Live long & prosper.

    The Dinosaur from prehistoric era prior to computers.

    Eschew obfuscation!
    If a billion people believe a foolish idea, it is still a foolish idea!
    VB.net 2010 Express
    64Bit & 32Bit Windows 7 & Windows XP. I run 4 operating systems on a single PC.

  5. #5

    Thread Starter
    New Member
    Join Date
    Sep 2000
    Posts
    3

    Complex Numbers

    To Guv,

    Thanks for that

    The algebra was all correct and the program worked perfectly. It draws quite an interesting fractal as well. Thanks for your help

    Dale

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width