Sunteți pe pagina 1din 3

A method in SQL to solve linear equations

Raymond Juillerat March 1, 2008


Abstract This article is typically an internet paper. It is published a rst time and will be completed later step by step. This little document presents a method implemented fully with MySql for solving linear equations.

Foreword
For a rapid estimation of some approximations regarding their validity, it may be interesting to solve a set of linear equations directly within the same environnement used to produce the basis matrix, i. e. a SQL environnement. Freeware doing this ist rather seldom to be found on the internet. Therefore this solution, implemented and tested in a MySql environnement. Such a solution was no realisable before stored procedures were implemented. Compared with other implementations, like with Oracle, there are some drawbacks, as an example, MySql doesnt allow a declaration of an inner procedure in a procedure. However, a migration to another db-system should be rather easy. 1

SQL

MySql

Solution of linear equations

1
1.1

Some features of the implementation


Stability of the estimations

This implementation is based on the Householder transform, which is known as beeing stable. Its requests more resources than a Gauss elimination, but offers against this drawback the advantage of a greater stability.

1.2

Flexibility of the method

The method can be used to solve a set of linear equations of any order. Only the execution time will differ following a cubic increase related to the order. This is a great advantage of a SQL-based solution compared with an algorithmic based one, coded in Pascal, for example.

2
2.1

Technical aspects
Description of the matrix

The equations are to be given in a table that describes the matrix. This entity is very simple, the attributes beeing column, row and coefcient. Column and row are integer values, the coefcients are double oating numbers. The values for attribute row are from 0 to (order-1). The values for attribute column are from 0 to order, the greatest one for the constants, meant as situated right to the equal sign. The table is a representation of the equations ani xn + a(n1)i xn1 + ... + a2i x2 + a1i x1 = consti
n1 i=0

where the row is equal to i and the column is equal to 0 for ani and n for consti .

2.2

The table of results

The results for the variables are brought to a vector. The table bearing this results is an entity composed of the attributes row and coefcient. Its also used for the reection vector necessary to perform the Householder transform.

2.3

About the package

The package[2] contains 4 les, the rst one (create_hh_tables.sql) containing the code creating the matrix and the vector that have to be dened in a rst step. The second le (hh.sql) contains the stored procedures as they has been used with MySql. The third le (hh_t.sql) and the last one (hh_simu.sql) contain each a small example. 2.3.1 Please dont reinvent the wheel

Its clear that the necessary explanations exist [1] without which this work was not possible. That paper gives a full explanation of the Householder algorithm and a solution written in Pascal. In the published codefor SQL a great part of the variables names are derived from that work, the SQL variable v_wii from the Pascal variable wii for example. The routinesnames are also derived from the Pascal proceduresnames. In the Housholder transformation the table-name hh_re_vect is the image of the mirroring vector vii. After the transformation it is used to put the result of the nal calculation on it.

rai.yul@suisse.org

english version

SQL

MySql

Solution of linear equations

References
[1] http://brinch-hansen.net/papers/1992a.pdf : Explanations of the Housholder transform with an implemention in Pascal P. Brinch Hansen, Householder reduction of linear equations, ACM Computing Surveys 24, 2 (June 1992), 185-194. Copyright c 1992, Association for Computing Machinery, Inc. [2] http://www.raym.org/sql/hh_package.zip

rai.yul@suisse.org

english version

S-ar putea să vă placă și