Click here to Skip to main content
13,150,178 members (28,515 online)
Click here to Skip to main content
Add your own
alternative version


172 bookmarked
Posted 9 Sep 2008

Mathemathics Framework

, 16 Sep 2008
Rate this:
Please Sign up or sign in to vote.
.NET Mathematical Framework


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.


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


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.


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:

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:

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.


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


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


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


About the Author

Engineer Universidad Tecnológica Nacional
Argentina Argentina
No Biography provided

You may also be interested in...

Comments and Discussions

GeneralWhat's it like being a dev in Argentina Pin
Ennis Ray Lynch, Jr.9-Sep-08 14:04
memberEnnis Ray Lynch, Jr.9-Sep-08 14:04 
GeneralRe: What's it like being a dev in Argentina Pin
gajatko13-Sep-08 1:05
membergajatko13-Sep-08 1:05 
GeneralRe: What's it like being a dev in Argentina Pin
homegrown15-Sep-08 6:47
memberhomegrown15-Sep-08 6:47 
GeneralRe: What's it like being a dev in Argentina Pin
gaesquivel16-Sep-08 12:35
membergaesquivel16-Sep-08 12:35 
GeneralPerfect! Pin
final_zero9-Sep-08 10:43
memberfinal_zero9-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.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.170924.2 | Last Updated 16 Sep 2008
Article Copyright 2008 by gaesquivel
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid