Click here to Skip to main content
15,886,056 members
Articles / Programming Languages / Visual Basic
Article

Class to handle complex numbers natively

Rate me:
Please Sign up or sign in to vote.
3.00/5 (9 votes)
6 Dec 20061 min read 24.1K   258   13   1
Over 100 methods, operators, and overloads.

Introduction

This is a different kind of complex number class for VB.NET than most of the ones I have seen. It is written so that the functions and operators can perform calculations natively by the calling class or method. It is indended to be highly extensible and easy to use.

For example, the arcSin function looks like this:

VB
Public Function arcSin(ByVal z As Complex) As Complex 
     Return -i * Ln((i * z) + Sqrt(1 - z ^ 2)) 
End Function

..and the inverse hyperbolic cosecant looks like this:

VB
Public Function arcCsch(ByVal z As Complex) As Complex
     Return Ln(Sqrt(1 + (1 / (z ^ 2))) + 1 / z)
End Function

These are the mathematical equations for complex numbers, and they will work for complex or real numbers. All 24 trigonometric and hyperbolic functions and their inverses are included in the source code.

Also included are operator and function overloads so that equations such as z+2 (mixing complex and real numbers (in this case doubles or integers)) is valid and allowed. Also perfectly valid are equations such as arcSin(2), where '2' is a real (Double) argument but the result is complex because there are no real number solutions for it.

Included is a class which contains the declarations, constructors, and operators, and a module which has all of the math code in it, and finally a Form class which provides some examples on how to declare and use the methods.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
NewsABS same as MAG Pin
Edward Giles3-Sep-11 20:07
Edward Giles3-Sep-11 20:07 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.