GaussDLL Library "JINRLIB" Author: I.N.Kiyan You are Language: C++ Environment: MS Visual C++ 7.0 visitor here. PROGRAM COMPLEX OF MATRIX-VECTOR OPERATIONS AND SOLUTION OF SLAE WITH REAL COEFFICIENTS GaussDLL is a C++ program complex written in MS Visual C++ 7.0 programming environment on the base of use of Microsoft Foundation Classes (MFC). It is intended for realization of matrix-vector operations and for decision of systems of the linear algebraic equations (SLAE) with real coefficients by a method of Gauss without and with pivoting. GaussDLL could be used if calling application makes calls to the MFC library at run time. User data type: CMatrix (arrays.h) CVector (arrays.h) Function return type: enum MatErrType { matErr_None, matErr_Size, matErr_Singular, matErr_IllConditioned, matErr_IterLimit, matErr_QNAN }; (arrays.h). matErr_None - correct solution, matErr_Size - error of size, matErr_Singular - error of singular, matErr_IllConditioned - error of ill conditionality, matErr_IterLimit - error of excess of limit of iteration number, matErr_QNAN - error of division by ziro. Exported functions: The functions, exported from GaussDLL library, allow to make account of norm of a vector, norm of a matrix, number of conditionality of system, left and right of rearrangement matrixes, sum and difference of two matrixes, products of a matrix on a vector and matrixes on a matrix, inverse matrix and determinant of a matrix. Besides they allow to make copying a vector, copying a matrix, and also transposition and Low / Up decomposition of the matrixes. Three functions are intended for the decision of systems of the linear algebraic equations with real coefficients by a method of Gauss, method of Gauss with column pivoting and method of Gauss with matrix pivoting accordingly. Left rearrangement matrix is used for rearrangement of rows in a matrix of coefficients and in a vector of the free members. Right rearrangement matrix is used for rearrangement columns in a matrix of coefficients and rows in a vector of the solution. The absolute value of the determinant of a matrix of coefficients should be more than e-15 (machine 0). 1. Norm of vector: void NormVec(double& norm, CVector& VecA, int numRowsA); Input parameters: VecA - source vector, numRowsA - number of rows of source vector. Output parameters: norm - norm of source vector. 2. Norm of matrix: void NormMat(double& norm, CMatrix& MatA, int numRowsA, int numColsA); Input parameters: MatA - source matrix, numRowsA - number of rows of source matrix, numColsA - number of columns of source matrix. Output parameters: norm - norm of source matrix. 3. Condition number of system: void SystCond(double normMat, double normInvMat, double& cond); Input parameters: normMat - norm of source matrix, normInvMat - norm of inverse matrix. Output parameters: cond - condition number of system. 4. Left rearrangement matrix: MatErrType RrrMatL(CMatrix& MatRes, int numRowsA, int rowInd, int colInd); Input parameters: numRowsA - number of rows of source matrix, rowInd - ziro based index of row of main element, colInd - ziro based index of column of main element. Output parameters: MatRes - left rearrangement matrix. 5. Right rearrangement matrix: MatErrType RrrMatR(CMatrix& MatRes, int numColsA, int rowInd, int colInd); Input parameters: numColsA - number of columns of source matrix, rowInd - ziro based index of row of main element, colInd - ziro based index of column of main element. Output parameters: MatRes - right rearrangement matrix. 6. Copying of vector: void CopyVec(CVector& VecA, CVector& VecB, int numRowsB); Input parameters: VecB - source vector, numRowsB - number of rows of source vector. Output parameters: VecA - destination vector. 7. Copying of matrix: void CopyMat(CMatrix& MatA, CMatrix& MatB, int numRowsB, int numColsB); Input parameters: MatB - source matrix, numRowsB - number of rows of source matrix, numColsB - number of columns of source matrix. Output parameters: MatA - destination matrix. 8. Addition of matrixes: MatErrType AddMat(CMatrix& MatA, CMatrix& MatB, CMatrix& MatC, int numRowsA, int numColsA, int numRowsB, int numColsB); Input parameters: MatA - first source matrix, MatB - second source matrix, numRowsA - number of rows of first source matrix, numColsA - number of columns of first source matrix, numRowsB - number of rows of second source matrix, numColsB - number of columns of second source matrix. Output parameters: MatC - sum of source matrixes. 9. Subtraction of matrixes: MatErrType SubMat(CMatrix& MatA, CMatrix& MatB, CMatrix& MatC, int numRowsA, int numColsA, int numRowsB, int numColsB); Input parameters: MatA - reduced matrix, MatB - deducted matrix, numRowsA - number of rows of reduced matrix, numColsA - number of columns of reduced matrix, numRowsB - number of rows of deducted matrix, numColsB - number of columns of deducted matrix. Output parameters: MatC - difference of two matrixes. 10.Transposition of matrix: void TransMat(CMatrix& MatA, CMatrix& MatRes, int numRowsA, int numColsA); Input parameters: MatA - source matrix, numRowsA - number of rows of source matrix, numColsA - number of columns of source matrix. Output parameters: MatRes - transposed matrix. 11.Multiplication of matrix and vector: MatErrType MulMatVec(CMatrix& MatA, CVector& VecB, CVector& VecC, int numRowsA, int numColsA, int numRowsB); Input parameters: MatA - source matrix, VecB - source vector, numRowsA - number of rows of source matrix, numColsA - number of columns of source matrix, numRowsB - number of rows of source vector. Output parameters: VecC - product. 12.Multiplication of two matrixes: MatErrType MulMatMat(CMatrix& MatA, CMatrix& MatB, CMatrix& MatC, int numRowsA, int numColsA, int numRowsB, int numColsB); Input parameters: MatA - left matrix, MatB - right matrix, numRowsA - number of rows of left matrix, numColsA - number of columns of left matrix, numRowsB - number of rows of right matrix, numColsB - number of columns of right matrix. Output parameters: MatC - product. 13.Low/Up decomposition: MatErrType LowUp(CMatrix& MatA, CMatrix& MatLow, CMatrix& MatUp, int numRowsA, int numColsA); Input parameters: MatA - source matrix, numRowsA - number of rows of source matrix, numColsA - number of columns of source matrix. Output parameters: MatLow - bottom triangular matrix, MatUp - top triangular matrix. 14.Determinant of matrix: MatErrType DetMat(CMatrix& MatA, double& det, int numRowsA, int numColsA); Input parameters: MatA - source matrix, numRowsA - number of rows of source matrix, numColsA - number of columns of source matrix. Output parameters: det - determinant. 15.Inverse matrix: MatErrType InverseMat(CMatrix& MatA, CMatrix& MatRes, int numRowsA, int numColsA); Input parameters: MatA - source matrix, numRowsA - number of rows of source matrix, numColsA - number of columns of source matrix. Output parameters: MatRes - inverse matrix. 16.Gauss method: MatErrType Gauss(CMatrix& MatLow, CMatrix& MatUp, CVector& VecIn, CVector& VecOut, int numRowsLow, int numColsLow, int numRowsUp, int numColsUp, int numRowsIn); Input parameters: MatLow - bottom triangular matrix, MatUp - top triangular matrix, VecIn - vector of free members, numRowsLow - number of rows of bottom triangular matrix, numColsLow - number of columns of bottom triangular matrix, numRowsUp - number of rows of top triangular matrix, numColsUp - number of columns of top triangular matrix, numRowsIn - number of rows of vector of free members. Output parameters: VecOut - vector of solution. 17.Gauss method with pivoting by column: MatErrType GaussPivCol(CMatrix& MatA, CVector& VecIn, CVector& VecOut, int numRowsA, int numColsA, int numRowsIn); Input parameters: MatA - source matrix, VecIn - vector of free members, numRowsA - number of rows of source matrix, numColsA - number of columns of source matrix, numRowsIn - number of rows of vector of free members. Output parameters: VecOut - vector of solution. 18.Gauss method with pivoting by table: MatErrType GaussPivTbl(CMatrix& MatA, CVector& VecIn, CVector& VecOut, int numRowsA, int numColsA, int numRowsIn); Input parameters: MatA - source matrix, VecIn - vector of free members, numRowsA - number of rows of source matrix, numColsA - number of columns of source matrix, numRowsIn - number of rows of vector of free members. Output parameters: VecOut - vector of solution. DLL function call (MS Visual C++ X.X): Declaring the global variable of handle to the module: HMODULE gGaussDLL; Definition of type of pointer to the function: typedef MatErrType (*GAUSSPIVTBL)(CMatrix& MatA, CVector& VecIn, CVector& VecOut, int numRowsA, int numColsA, int numRowsIn); Declaring the global pointer to the function: GAUSSPIVTBL pGaussPivTbl; Loading the DLL (in constructor): gGaussDLL = LoadLibrary("GaussDLL"); Retrieving the address of an function exported by DLL (in constructor): pGaussPivTbl = (GAUSSPIVTBL)GetProcAddress(gGaussDLL, "GaussPivTbl"); Declaring the local variable and call of the exported function: MatErrType ErrCode; ErrCode = pGaussPivTbl(MatA, VecIn, VecOut, MatA.getRows(), MatA.getCols(), VecIn.getSize()); Unloading the DLL (in destructor): FreeLibrary(gGaussDLL); Archive GaussDLL (GaussDLL.dll, mfc70.dll, ARRAYS.H, test, example and description) are submitted. |