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.)
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)
Public Shared Operator -(ByVal Z1 As Complex, ByVal Z2 As Complex) As Complex
Return New Complex(Z1.Real - Z2.Real, Z1.Imaginary - Z2.Imaginary)
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:
Dim a, b, c As Complex
a.Real = 10
b.Imaginary = 5
c = a + b
As seen in the second last line, the addition
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
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.
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:
Both of these functions are evaluated in the interval (0,10).
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:
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.
On the other hand, obtaining the root locus diagram for Laplace transform functions is possible.
For example, given the function:
Its locus root diagram is shown in Fig. 5
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.
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.
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:
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
Some others interestings 3D images:
Special Thanks to Daniel Pelletieri
Thanks to Osvaldo Pini
Thanks to Alejandro Furfaro
Thanks to Oscar Noguez