Custom handle complex numbers in NET

New product

In this article we show how to make a custom structure for flexible handling of complex numbers using NET Framework and Visual Basic NET

Hello, in this opportunity, I am going to create a data structure that can control complex numbers in a much more flexible way. Now, open those who say that the NET Framework has this structure already implemented, but in my opinion it needs more functionality and that is why I decided to develop my own and share it in this way.

What did I need to add to the structure?

- Functionality to read the numbers in the form of a chain.

- Functionality for presentation in polar and rectangular.

- Basic arithmetic operations with custom operators.

- Automatic transformation Polar-> Rectangular and vice versa.

 

How is it used?

I thought it quite simple to use:

Construction

To start the complex number is done as follows:


Build a complex number (2 <30º) in Polar

  'Using the explicit constructor
Dim NumComplejoA = New NumeroComplejo(2, 30, True)
'Using the string builder
Dim NumComplejoB = New NumeroComplejo("2@30")

 

Build a complex number (2 + 3i) in Rectangular

  'Using the explicit constructor
Dim NumComplejoC = New NumeroComplejo(2, 3)
'Using the string builder
Dim NumComplejoD = New NumeroComplejo("2+3i")

 

As you can see, it is quite simple to do it and it is important not to be confused with the explicit constructor since the third parameter is optional and tells the constructor what kind of complex number it is going to build.

Algebraic operations

Once the complex number is constructed, algebraic operations are simple and can be performed in the same code:

   Resp = NumComplejoA + NumComplejoB  'Return the sum
Resp = NumComplejoC - NumComplejoA 'Return the subtraction
Resp = NumComplejoC ^ 2 'returns pow 2

 

Important notes:

Some of the things to take into account when using this structure are the following:

The string constructor understands the decimal notations both by comma (,) and by period (.) But at the end it makes the conversion using the key function csng () that uses system notation. This means that if you type (1.2 + 12i) and the regional configuration of the system is configured to use comma (,) there will be a syntax error.

The ToString () function was overwritten to show the number in polar or rectangular notation. This depends on the static property Presentation.

Another important thing is that the chain constructor understands the rectangular notations of the form (a + bi) and also (a + ib). The latter is used in electrical / electronic engineering.

The source code:

Here I show you a video where I explain how to use the engine and the final recommendations.

Well, see ya. If you add something else or have any questions please let me know by writing below in questions.

See you another time. ; )

Written by:

Elimar Garcia

19/12/2017

Grade 
12/19/2017

Excelente lección.

Me gusto

Write your review!

Write a review

Custom handle complex numbers in NET

Custom handle complex numbers in NET

In this article we show how to make a custom structure for flexible handling of complex numbers using NET Framework and Visual Basic NET

Ask a question

NO registration required!

If the question you have has not yet been answered here, use the form below to ask something about this addon.

(optional)
*(Required to be notified when an answer is available)

If the download link redirects to another product that is not described in the article or is broken, report it using our Reporting Form

RelatedProducts