USING LAPACK SOLVERS FOR STRUCTURED MATRICES

2y ago
17 Views
2 Downloads
231.29 KB
5 Pages
Last View : 1d ago
Last Download : 2m ago
Upload by : Madison Stoltz
Transcription

USING LAPACK SOLVERS FOR STRUCTURED MATRICES WITHIN MATLABRadek Frízel*, Martin Hromčík**, Zdeněk Hurák***, Michael Šebek****Department of Control Engineering, Faculty of Electrical Engineering,Czech Technical University in Prague, Czech Republic**Centre for Applied Cybernetics, Czech Technical University in Prague,Czech Republic***Institute of Information Theory and Automation, Czech Academy of Sciences,Czech RepublicAbstractLinear polynomial equations, also called Diophantine in the systems and controlliterature, are often needed to design a dynamic feedback controller or compensator.Solving these equations numerically leads to special Toeplitz type sets of linear equations.To solve them, one can naturally call the general purpose solvers build in the standardMATLAB distribution. Another, and potentially more effective way, is to employ dedicatedroutines of the well known LAPACK library that exploit the structure of the problem to savecomputational time and memory requirements. This paper describes the experience of theauthors with this approach.IntroductionWe compute the solution to a real system of the polynomial Diophantine equationax by c in Matlab, through the Sylvester matrix method using external solver. Weconstruct band matrix A with sylvestr structure and compute the solution AX C using externsolver, Lapack’s functions. Matrix A is special band matrix identified with two columns, join oftwo Toeplitz matrices, B is matrix of right side and X is solution contains x and y from thepolynomial Diophantine equation.For using lapack’s functons in Matlab we need MEX-file. This file can be written in theprogramming language C or Fortran. MEX-file is gate between Matlab and functions fromLapack library. In this gate arguments to be solved are passed from Matlab to and fromLapack’s functions; they must be passed by reference. Calling the well known Lapack library(also called external solver) is well described for example in Matlab Help or in [2].We use lapack’s functions to solve a system of linear equations AX B or A'X B with ageneral band square matrix A using the LU factorization. Lapack library doesn’t containfunctions which solve general band rectangle matrix. For wolving these matrices we use QRfactorization from Lapack library. But this factorization is for general matrices and that is notwhat we really wanted, exploit the structure of matrix.

ImplementationWe create MEX-files in the programming language C under Windows. We use thelapack library, which is part of Matlab. This Lapack library isn’t optimalized but for first stepsit’s enought. Later is better work under Linux and instal optimalization Lapack library.How to create a MEX-file we show on example of calling lapack function which solvea system of linear equations AX B or A'X B with a general band square matrix A using theLU factorization. MEX-file contains one function mexFunction, which is interface betweenMatlab and lapack functions. This mex function has four parameters: number of inputparameters, array of pointers to input parameters, numbers of output parameters and arrayof pointers to output parameters. To retrieve the values of input parameters and store theminto local variables mexFunction uses appropriate Matlab fuctions. When it’s done we callthe lapack function. The pointers to output are stored to array of the mexFuction and thelocal arrays are destroyed.Code of MEX file GenBand:#include "mex.h"void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]){double *AB, *B, *IPIV, *temp, *temp1, *temp2, *temp3, zero 0.0;int LDAB, KL ,KU, M, N, Info, k, LDB, NRHS;char msg[100], *TRANS "N";// Check the imput parameters:if (nrhs ! 4){mexErrMsgTxt("Four input arguments required.");} else if (nlhs 2){mexErrMsgTxt("Too many output arguments.");};// Retrieve the values of input parameters:M mxGetM(prhs[0]);N mxGetN(prhs[0]);AB mxCalloc (M*N, sizeof(double));temp mxGetPr(prhs[0]);for (k 0;k N*M;k ){AB[k] temp[k];};LDAB M;if (!mxIsDouble(prhs[2]) mxIsComplex(prhs[2]) mxGetN(prhs[2])*mxGetM(prhs[2]) ! 1) {mexErrMsgTxt("Input KL must be a scalar.");}KL mxGetScalar(prhs[2]);if (!mxIsDouble(prhs[3]) mxIsComplex(prhs[3]) mxGetN(prhs[3])*mxGetM(prhs[3]) ! 1) {mexErrMsgTxt("Input KU must be a scalar.");}KU mxGetScalar(prhs[3]);IPIV mxCalloc (N,sizeof(double));// Call the first lapack fuction:dgbtrf(&M,&N,&KL,&KU,AB,&LDAB,IPIV,&Info);

// Check errors:if (Info zero){sprintf(msg,"Input %d to DGBTRF had an illegal value",-Info);mexErrMsgTxt(msg);};// Retrieve the values of input parameters to second lapack functin:LDB mxGetM(prhs[1]);NRHS mxGetN(prhs[1]);B mxCalloc(LDB*NRHS, sizeof(double));temp2 mxGetPr(prhs[1]);for (k 0; k LDB*NRHS; k ) {B[k] temp2[k];}Info 0;// Call the second lapack fuction:dgbtrs(TRANS, &N, &KL, &KU, &NRHS, AB, &LDAB, IPIV, B, &LDB, &Info);// Check errors:if (Info zero) {sprintf(msg,"Input %d to DGBTRS had an illegal value",-Info);mexErrMsgTxt(msg);}// Create matrix for the return arguments:plhs[0] mxCreateDoubleMatrix(M,N,mxREAL);temp1 mxCalloc(M*N, sizeof(double));for (k 0; k M*N; k ){temp1[k] AB[k];}mxSetPr(plhs[0],temp1);plhs[1] mxCreateDoubleMatrix(LDB,NRHS,mxREAL);temp3 mxCalloc(LDB*NRHS, sizeof(double));for (k 0; k LDB*NRHS; k ) {temp3[k] B[k];}mxSetPr(plhs[1],temp3);// Free o compile and link the MEX file at the Matlab prompt, type:mex GenBand.c.Matlab produces file GenBand.dll, which can be called in the same manner as a standardMatlab m-file.There are some possible problems you could meet if you want to call lapack functionsfrom your mex file. The variables which are used as input parameters to lapack functionsmust be of the correct types (double, int etc.). All local arrays must be destroy (free) at theend.

Experimental testingWe compare standard function of Matlab, left matrix division, and external solver,Lapack function, dgbtrs, in solving of linear equations AX B, A is general square bandmatrix. Measured values are shown in the graph 1.Graph 1: How depends execute time of both method on band width. ("*" representability Matlab'sfunction and "o" representability external solver.) Order of matrix is: a) 500, b) 1000, c) 1500, d)2000.We compute the solution to a real system of the scalar polynomial Diophantineequation ax by c in Matlab, through the Sylvester matrix method using external solver.Measured values are shown in the graph 2.ConclusionThe external solver is faster than general purpose solver build in standard MATLABdistribution. We make sure about that with experimental testing. Now we need to solveAX B, where A is general band rectangle matrix. We trying use another function from lapacklibrary in which we can utilize known structure of matrix. For example Lapack function withdecomposition of rectangle band matrix to bidiagonal square matrix multiplying with twoorthogonal square matrices, A Q*Ab*P'.

Graph 2: How depends execute time of both method on degree of polynoms. (" "representability Matlab's function and "o" Lapack library function.)AcknowledgmentThe work of R.Frízel has been supported by the Ministry of Education of the CzechRepublic under contract No. INGO LA156. The work of M. Hromčík has been supported bythe Ministry of Education of the Czech Republic under contract No. LN00B096. The work ofZ.Hurák and M.Šebek has been supported by the Ministry of Education of the CzechRepublic under contract KONTAKT No. ME496.Reference[1] LAPACK – Linear Algebra PACKage [online]. http://www.netlib.org/lapack[cite 2004-04-29][2] Using LAPACK and BLAS Functions help/techdoc/matlab external/matlab external.html[cite 2004-04-29][3] HAVLENA, V. (1999). Moderní teorie řízení - Doplňkové skriptum. Vydavatelství ČVUT,Praha.

Matlab and lapack functions. This mex function has four parameters: number of input parameters, array of pointers to input parameters, numbers of output parameters and array of pointers to output parameters. To retrieve the values of input parameters and store them into local variables mexFu

Related Documents:

chapter surveys the organization of CDCL solvers, from the original solvers that inspired modern CDCL SAT solvers, to the most recent and proven techniques. The organizationof CDCL SAT solvers is primarily inspired by DPLL solvers. As a result, and even though the chapter is self-contained, a reasonable knowledge of the organization of DPLL is .

The Linear Algebra PACKage (LAPACK) and the Scalable Linear Algebra PACKage (ScaLAPACK), referred to in combination as Sca/LAPACK, are community standards for dense linear algebra and have been adopted and/or supported by a large community of users, computi

Bruksanvisning för bilstereo . Bruksanvisning for bilstereo . Instrukcja obsługi samochodowego odtwarzacza stereo . Operating Instructions for Car Stereo . 610-104 . SV . Bruksanvisning i original

10 tips och tricks för att lyckas med ert sap-projekt 20 SAPSANYTT 2/2015 De flesta projektledare känner säkert till Cobb’s paradox. Martin Cobb verkade som CIO för sekretariatet för Treasury Board of Canada 1995 då han ställde frågan

service i Norge och Finland drivs inom ramen för ett enskilt företag (NRK. 1 och Yleisradio), fin ns det i Sverige tre: Ett för tv (Sveriges Television , SVT ), ett för radio (Sveriges Radio , SR ) och ett för utbildnings program (Sveriges Utbildningsradio, UR, vilket till följd av sin begränsade storlek inte återfinns bland de 25 största

Hotell För hotell anges de tre klasserna A/B, C och D. Det betyder att den "normala" standarden C är acceptabel men att motiven för en högre standard är starka. Ljudklass C motsvarar de tidigare normkraven för hotell, ljudklass A/B motsvarar kraven för moderna hotell med hög standard och ljudklass D kan användas vid

LÄS NOGGRANT FÖLJANDE VILLKOR FÖR APPLE DEVELOPER PROGRAM LICENCE . Apple Developer Program License Agreement Syfte Du vill använda Apple-mjukvara (enligt definitionen nedan) för att utveckla en eller flera Applikationer (enligt definitionen nedan) för Apple-märkta produkter. . Applikationer som utvecklas för iOS-produkter, Apple .

Answer a is too narrow to be the implied idea. It is based on only one of the four supporting details, statement 1. b. Answer b covers only statements 2 and 4; therefore it is too narrow to be the implied main idea. In addition, it is a conclusion that is not based on the given facts, which say nothing about one group always being better than another. c. Answer c is a general statement about .