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

Mathemathics Framework

Rate me:
Please Sign up or sign in to vote.
4.76/5 (56 votes)
16 Sep 2008CPOL6 min read 75.1K   6.2K   171   16
.NET Mathematical Framework

Introduction

This work shows a summary of the success we have reached developing libraries for mathematic, scientific and engineering applications using Microsoft’s .NET platform and the graphics library DirectX.

Requisites

To run the Demo application or Compile the source code you must first install this:
- DirectX 9.0c Redist

Features

Bodeviewer was designed for drawing 2D and 3D mathematical functions of different kinds, like:

  • Complex variable mathematic type
  • 2 variable mathematic type
  • Real variable mathematic type
  • External real physics type (like sound wave, temperature variation, etc.)
  • Other…

Bodeviewer was intended for students, teachers and researchers, but is not finished yet.

Background

While teaching Applied Electronics I and II, we usually study the behavior of circuits with graphic analysis responding to circuit equations.

Unfortunately, many of the software solutions available some years ago were neither efficient nor simple. In addition, only a few students could afford them, because of the high cost of the educational software.

The main objective at that moment was the creation of one Windows app (in VB) to draw Bode´s graphs for complex variable functions, from its poles and zeros specification. The good results achieved conducted us to the work we describe here.

For example, to define the complex number type, we can write one simple structure as follows:

VB
Public Structure Complex

    Public Real As Double
    Public Imaginary As Double

    Public Shared Operator +(ByVal Z1 As Complex, ByVal Z2 As Complex) As Complex
        Return New Complex(Z1.Real + Z2.Real, Z1.Imaginary + Z2.Imaginary)
    End Operator

    Public Shared Operator -(ByVal Z1 As Complex, ByVal Z2 As Complex) As Complex
        Return New Complex(Z1.Real - Z2.Real, Z1.Imaginary - Z2.Imaginary)
    End Operator
End Structure

In this elemental example, the structure has two member variables – or fields – Real and Imaginary, that will store the real and imaginary part of numbers that they represent. Moreover, we have defined two operators for the complex variables addition and subtraction just like whatever numeric type. For example:

VB
Sub SomeCode()

    Dim a, b, c As Complex

    a.Real = 10
    b.Imaginary = 5
    c = a + b

End Sub

As seen in the second last line, the addition a plus b is assigned to c using the + operator, defined into the structure, with a real clear syntax. We can get more versatility to the structure wearing properties instead of fields, because they allow the code inclusion. This choice allows more capacities to this pseudo field.

Also, the inherited members were re-used and replaced. For example, the ToString function. Now, this function returns one string with R + i I format, where i is the imaginary unit, R the real component and I the imaginary component of a complex number. After all modifications and add-ons, and after being renamed to ComplexUndefinied, the structure shows the appearance shown in Fig. 1.

Figure 1: Class Diagram of ComplexUndefinied  structure

Figure 1: Class Diagram of ComplexUndefinied structure

Using properties can be appreciated, in order to have other features of complex numbers, i.e. module and phase, calculated (transparently for users) from the real and imaginary part stored in the structure.

There are a spread variety of implemented methods. For example, the method GetConjugated. This obtains an instance of the conjugated value of the examined complex number. Another example is the FromString method, which allows you to get the string value of a complex number in mathematical format, where i is the imaginary unit, R is the real part and I is the imaginary part.

So, creating a library for a complex numbers operation is not so difficult after all we have shown here. In a relatively short time we have a complete “bunch” of accessory classes to manipulate this and other data types, and to show the results in the desired manner as well.

In order to get functions from conventional mathematic symbols, a class including string parser methods was created, added to a whole class architecture representing mathematic functions, centrally administrated for this one. This allows composite functions, i.e. functions depending on other functions.

Also, we have considered that some function types, not based in habitual mathematic expressions, could be necessary in the future. For example, the functions expressed by Laplace transform, defined from its poles and zeroes, supported by our libraries.

To visualize the functions, and as an extra way to verify the results, complex libraries of controls, named Visualizators, were created. Visualizators accept data in different formats, and are capable of presenting the results with style or scale which investigators require.

.NET Framework versatility, combined with its development environment allows implementing complementary functions for function analysis and 2D graphics, like classes for FFT (Fast Fourier Transform) analysis, or one class to manipulate cursors. In addition, we have developed zoom tools for the comfortable interaction with graphs, and objects to find the roots location in one given interval, which all kinds of configuration options are easily set by users.

Finally, make note that using the Microsoft graphic libraries DirectX (usually employed in the fastest PC games) we could get an optimal 3D representation of complex variable functions (with two or more variables), that actually can be manipulated in real time by users.

Results

Picture 2 shows a view of the main application.

main application

It is a typical Windows app (called form) with toolbars and option menus allowing fast access to every accessory tool described before. The viewer has several tabs to allow watching 2D and 3D graphs of functions. Figure 3 shows the detail of one lineal scale viewer with two real functions data; to be exact, the first is a cosine function and the other is a parabola whose expression is:

Sample Image - maximum width is 600 pixels 

Both of these functions are evaluated in the interval (0,10).

y = cos(x) and y = 0.01P*x^2-x+1

Figure 3 2D Visualization of functions y = cos(x) and y = 0.01P*x^2-x+1

Besides, to specify another scale type in the viewer is possible. For example, logarithmic scales for the two axes can be set. This is shown in Fig. 4, where we can appreciate the module Bode graph of one transfer function, A, the feedback, B (usually called beta), and the Af closed loop output, defined as:

y = cos(x) and y = 0.01P*x^2-x+1

Where z is the independent complex variable and Af is a composed function. In this case, we can see the positive feedback peak close to 1MHz for the circuit represented with the functions upper mentioned.

Open loop Transfer, Feedback and Closed loop Transfer

On the other hand, obtaining the root locus diagram for Laplace transform functions is possible.

For example, given the function:

Open loop Transfer

Its locus root diagram is shown in Fig. 5

Root Locus

In Fig. 5 we can see the poles location represented with crosses, while its trajectory for different feedback levels is represented with circles. With regard to a Fourier analysis of functions, we can see the response for unitary amplitude and width pulse, as well its FFT in Figs. 6 and 7.

Unitary amplitude Pulse Fourier Transfor (FFT) of such Pulse

Here is one last example of 2D functions viewing in Fig. 8, where we can see the tool for real roots searching in a given interval. In this visualization, it appears the searching range and rectilinear traces that explains the used method. In this case, the Regula Falsi method was used. In another section of the app, it informs that the root was located in x=3.141593.

Searching real roots tool graph

Now we will analyze some examples of 3D viewer. For the case of two variables functions, we show in Fig. 9 the hemisphere graph given by the expression:

Searching real roots tool graph

Figur9 3D graph of a hemisphere

For complex variable functions we have first taken one expression including one trigonometric function as one sine. For example, the graph for the module of G(z)=sin(0.3*z) is shown in Fig. 10

Figure 10: 3D view of a complex variable function

Some others interestings 3D images:

3D view of a complex function with 3 poles 3D view of a complex Logarithm function

Credits

Special Thanks to Daniel Pelletieri
Thanks to Osvaldo Pini
Thanks to Alejandro Furfaro
Thanks to Oscar Noguez

License

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


Written By
Engineer Universidad Tecnológica Nacional
Argentina Argentina
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralMy vote of 5! Pin
Filip D'haene19-May-11 5:58
Filip D'haene19-May-11 5:58 
GeneralGood Pin
peretog7-May-09 14:46
peretog7-May-09 14:46 
GeneralWonderful Pin
java300016-Oct-08 4:33
java300016-Oct-08 4:33 
GeneralRe: Wonderful Pin
gaesquivel16-Oct-08 6:26
gaesquivel16-Oct-08 6:26 
GeneralMissing Source Files Pin
dgauerke11-Sep-08 3:44
dgauerke11-Sep-08 3:44 
GeneralRe: Missing Source Files Pin
gaesquivel11-Sep-08 5:27
gaesquivel11-Sep-08 5:27 
GeneralRe: Missing Source Files Pin
ww20715-Sep-08 9:48
ww20715-Sep-08 9:48 
GeneralRe: Missing Source Files Pin
gaesquivel15-Sep-08 11:19
gaesquivel15-Sep-08 11:19 
GeneralRe: Missing Source Files Pin
gaesquivel16-Sep-08 12:28
gaesquivel16-Sep-08 12:28 
Hi again.

The updates are ready!!!

Respect the source code, I suggest you to create first a directory called for example “BV”, and move all directories extracted to this, except the directory called “\GGLibs\”. This must be at the same level of the directory “\BV\”.

Thus you could open and load the solution without any inconvenience. The Directory tree must be:

\BV\....
….
….
\GGLibs\....

Tell me if something don’t work
GeneralRe: Missing Source Files Pin
gaesquivel11-Sep-08 6:01
gaesquivel11-Sep-08 6:01 
GeneralRe: Missing Source Files Pin
Said122-Sep-21 18:48
Said122-Sep-21 18:48 
GeneralWhat's it like being a dev in Argentina Pin
Ennis Ray Lynch, Jr.9-Sep-08 14:04
Ennis Ray Lynch, Jr.9-Sep-08 14:04 
GeneralRe: What's it like being a dev in Argentina Pin
Lutosław13-Sep-08 1:05
Lutosław13-Sep-08 1:05 
GeneralRe: What's it like being a dev in Argentina Pin
homegrown15-Sep-08 6:47
homegrown15-Sep-08 6:47 
GeneralRe: What's it like being a dev in Argentina Pin
gaesquivel16-Sep-08 12:35
gaesquivel16-Sep-08 12:35 
GeneralPerfect! Pin
Aamer Alduais9-Sep-08 10:43
Aamer Alduais9-Sep-08 10:43 

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.