Download and tutorial (we will probably install and use these two files)
Clapack: http://icl.cs.utk.edu/lapack-for-windows/clapack/index.html
LAPACK: http://icl.cs.utk.edu/lapack-for-windows/lapack/#libraries_mingw
(Put the downloaded file in the appropriate directory of)
----
Clapack is the C language interface of LAPACK. LAPACK, short for Linear Algebra package, is a well-known linear algebra library. LAPACK is written in FORTRAN. To facilitate the use of C/C ++ programs, the lapack c interface library clapack is available. The home page of LAPACK is http://www.netlib.org/lapack/. the main page of clapackis http://www.netlib.org/clapack /.
Clapack is available in Linux and Windows. To install clapack-Windows, first download the clapack-Windows package from its home page, decompress the package, and use VC (vs2005) to open clapack. DSW. Clapack. h under clapack is the required header file. In addition, a header file is f2clibs/f2c. h.
Now we can use a function sgesv _ in clapack to solve the linear equations.
All functions, including this function, can find the source code under clapack/src, and have descriptions of function parameters in the code. The sgesv _ code file is sgesv. C.
Int sgesv _(Integer * n, integer * nrhs, real * a, integer * Lda, integer * IPIV, real * B, integer * LDB, integer * info)
Sgesv _ uses the Lu Decomposition Method to Solve the linear equations Ax = B, where A is a matrix of N * n.
Integer * n, number of equations, number of rows and number of columns of
Number of columns of integer * nrhs and B
Real * A: A one-dimensional array that stores matrix A data. In FORTRAN, arrays are primary column orders, and the two-dimensional data in matrix A must also be primary column orders.
Integer * Lda, equal to n
Integer * IPIV: an array of output data. The array size is N. The function does not seem to affect the final result.
Real * B: One-dimensional array for storing matrix B data. In FORTRAN, arrays are primary column orders, and the two-dimensional data in matrix B must also be primary column orders.
Integer * LDB, equal to n
Integer * info: output parameter. If the return value is 0, the function Exits normally. Otherwise, an error occurs.
The following code is used:
1 // mytest. CPP: defines the entry point for the console application. 2 // 3 4 # include "stdafx. H "5 6 # include <iostream> 7 8 using namespace STD; 9 10 # include <f2clibs/f2c. h> 11 12 // because the program is C ++ and clapack is written in C, the extern keyword 13 extern "C" 14 {15 # include <clapack. h> 16} 17 18 19 int _ tmain (INT argc, _ tchar * argv []) 20 {21 integer m = 3; 22 integer n = 1; 23 real a [9] = {,-, 3}; 24 Real B [3] = {, 8}; 25 integer LDA; 26 integer LDB; 27 integer Info; 28 29 LDA = m; 30 LDB = m; 31 integer * IPIV; 32 IPIV = (integer *) New integer [m]; 33 34 sgesv _ (& M, & N, A, & Lda, IPIV, B, & LDB, & info); 35 36 IF (Info = 0) 37 {38 for (INT I = 0; I <m; I ++) 39 {40 cout <B [I] <Endl; 41} 42} 43 else44 {45 cout <"failed. "<Endl; 46} 47 48 return 0; 49} 50 51
When compiling a link, add clapack. lib to the link library.
[Transfer] http://hi.baidu.com/xuyungui/blog/item/c43ef9026e8cff713912bbd3.html