A Scientific Computation LibraryKy Van Ha
1. IntroductionScientific Computation becomes more and more important to our students. A Scientific Computation Library (SCL) that they can use in their applications is clearly of interest. I started a project six months ago. The goal is to develop a scientific computation library with C++ which handles some problems in Applied Mathematics, Numerical Analysis, Graphics, Signal Processing, Image Processing, Wavelet Analysis, Neural Network, etc.The Library will be updated and expanded each year, and a document will be made to report on the new results. In order that such a library can be succesfully developed,many people, students and colleagues, must be hopefully involved. The Library that is on the net now is really an extension of the Graphics Library I developed last year, see [1], it contains more than 150 functions. The Library has two versions, one for DOS and one for Windows. The Library has been contructed and tested with Borland C++4.5, using the standard API functions. Thus, with a little change, it can be used for other compilators as Microsoft C++ as well. In this paper, I would like to give some examples to show how one can use that library in Windows Applications, see [1] and [2] for more detail.
2. Compile an application with SCLThere are fives prototypes files one can use. These files are on the drive "I" under the directory "bc45\include\kvh" :kvh_def.h : Global definitions and macros kvh_wmat.h : Mathematical routines kvh_wgrp.h : Graphics routines kvh_wnum.h : Numerical routines kvh_wsgn.h : Signal and wavelet routinesIn order to compile your application with the SCL, you must :
When you write a scientific program, a book like " Numerical Recipe in C" (see [3]) is of course very helpful. But the book is not easy for everybody. With the SCL, you can just call the functions that are defined in the prototype files from your programs. In the following sections, some examples about graphics, mathematics and signal processing will be given using the scientific computation library. These examples demostrate also how one can write a Windows program with Borland C++4.5
3. Using the numerical routinesThe following program will solve the linear system Mx = b using LU factorization.
The program is a standard Windows program. The Paint function will
write the results in the windows after it called the function
"Linear_System(x)" that we define in the beginning of the
program. That function calls two numerical routines defined in the SCL:
The solutions are stored in the array x. Write it to a string
Msg, and use DC.TextOut function to write this
string to Windows.
The result is 3.000 1.000 -2.000 1.000 4. Using the graphics routinesIn the next example, we would like to interpolate a data set using B-spline technique. You can define a class, say TBspline, that does everything for you. It can generate a B-spline curve, interpolate a data set, approximate a function, compute derivative, integral by calling the very technical routines in the SCL.
Let us look at an example. To implement the function Bspl_Inter(x, y),
where x, y are two arrays which contain the coordinates of the data
points, we will call the B-spline routines from the SCL.
In order to use the TBspline class, we have to write a function in our application, say DrawCurve, which will interpolate data points and draw a B-spline curve through these points. Here is an example:
The result is shown in the figure 1.
5. Using the signal processing routinesTo design a filter is a common problem in signal processing. In the following esample, we will design a Lowpass Filter based on Kaiser Window. The program will compute the impulse response h(n) of the filter with the following design specifications:
(see [4], kap. 3). The program calls first the routine:
that computes the Kaiser window parameters, and then use the parameter
"beta" and the modified zeroth-order Bessel function to
compute the Kaiser window function v(n). And finally it
computes the impulse response h(n). The following codes do that
jobb.
The impulse response of the filter is displayed in figure 2.
References
Copyright: 1996, Høgskolen i Østfold. Last Update: 28.06.97, Thomas Malt. |