lin_eq_with_sql
TRANSCRIPT
-
7/27/2019 lin_eq_with_sql
1/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 first 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
-
7/27/2019 lin_eq_with_sql
2/3
SQL MySql Solution of linear equations
1 Some features of the implementation
1.1 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 Technical aspects
2.1 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 coefficient. Column and row are integer values, the coefficients
are double floating 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
anixn + a(n1)ixn1 + ...+ a2ix2 + a1ix1 = 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 com-
posed of the attributes row and coefficient. Its also used for the reflection vector necessary to perform
the Householder transform.
2.3 About the package
The package[2] contains 4 files, the first one (create_hh_tables.sql) containing the code creating the
matrix and the vector that have to be defined in a first step. The second file (hh.sql) contains the stored
procedures as they has been used with MySql. The third file (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 final
calculation on it.
[email protected] 2 english version
-
7/27/2019 lin_eq_with_sql
3/3
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, ACMComputing Surveys 24, 2 (June 1992), 185-194. Copyright c1992, Association for Computing
Machinery, Inc.
[2] http://www.raym.org/sql/hh_package.zip
[email protected] 3 english version