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
Printable View
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
Doubt it!
But tell me what you have in mind to do with complex numbers
(if you don't mind)
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...
You can program complex arithmetic. I suggest Functions for +, -, *, & / used with a Type defined as complex. Something like the following.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.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
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.
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