diff options
author | siddhu8990 | 2017-04-13 10:42:02 +0530 |
---|---|---|
committer | siddhu8990 | 2017-04-13 10:42:02 +0530 |
commit | 160eb350837f8cd3cdb0943b5929e11f44036826 (patch) | |
tree | 5b8166b0ec4aca53df11365f8be96ac07088558f /2.3-1/src/c/linearAlgebra | |
parent | e59107e6bb2695fc20fd0ab229e296b9bf739fc4 (diff) | |
download | Scilab2C-160eb350837f8cd3cdb0943b5929e11f44036826.tar.gz Scilab2C-160eb350837f8cd3cdb0943b5929e11f44036826.tar.bz2 Scilab2C-160eb350837f8cd3cdb0943b5929e11f44036826.zip |
Functions added - balance,rcond,obscont
Diffstat (limited to '2.3-1/src/c/linearAlgebra')
-rw-r--r-- | 2.3-1/src/c/linearAlgebra/balanc/dbalanca.c | 75 | ||||
-rw-r--r-- | 2.3-1/src/c/linearAlgebra/includes/balanc.h | 27 | ||||
-rw-r--r-- | 2.3-1/src/c/linearAlgebra/includes/rcond.h | 26 | ||||
-rw-r--r-- | 2.3-1/src/c/linearAlgebra/interfaces/int_balanc.h | 29 | ||||
-rw-r--r-- | 2.3-1/src/c/linearAlgebra/interfaces/int_rcond.h | 25 | ||||
-rw-r--r-- | 2.3-1/src/c/linearAlgebra/rcond/drconda.c | 46 | ||||
-rw-r--r-- | 2.3-1/src/c/linearAlgebra/schur/dschura.c | 2 |
7 files changed, 229 insertions, 1 deletions
diff --git a/2.3-1/src/c/linearAlgebra/balanc/dbalanca.c b/2.3-1/src/c/linearAlgebra/balanc/dbalanca.c new file mode 100644 index 00000000..558c6149 --- /dev/null +++ b/2.3-1/src/c/linearAlgebra/balanc/dbalanca.c @@ -0,0 +1,75 @@ +/* Copyright (C) 2017 - IIT Bombay - FOSSEE + + This file must be used under the terms of the CeCILL. + This source file is licensed as described in the file COPYING, which + you should have received as part of this distribution. The terms + are also available at + http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt + Author: Siddhesh Wani + Organization: FOSSEE, IIT Bombay + Email: toolbox@scilab.in + */ + +/*Funtion to balance given square matrix to improve its condition number*/ +#include "balanc.h" +#include "lapack.h" +#include "stdlib.h" +#include "string.h" +#include "eye.h" + +void dbalanca(double* in1, int rows, double* in2, double* out1, \ + double* out2, double* out3, double* out4) +{ + char JOB = 'B'; + char RSIDE = 'R'; + char LSIDE = 'L'; + + int ILO, IHI, INFO; + double *buf1, *buf2, *LSCALE, *RSCALE; + double *LWORK; + + + if(in2 == NULL) + { + /*Single input matrix*/ + buf1 = (double*) malloc((double) rows*rows*sizeof(double)); + LSCALE = (double*) malloc((double) rows*sizeof(double)); + + /*copy input to temp buf as lapack function modifies input*/ + memcpy(buf1,in1,rows*rows*sizeof(double)); + + dgebal_(&JOB,&rows,buf1,&rows,&ILO,&IHI,LSCALE,&INFO); + deyea(out2,rows,rows); + dgebak_(&JOB,&RSIDE,&rows,&ILO,&IHI,LSCALE,&rows,out2,&rows,&INFO); + + /*copy computed matrix to output*/ + memcpy(out1,buf1,rows*rows*sizeof(double)); + } + else + { + /*two matrices as inputs*/ + buf1 = (double*) malloc((double) rows*rows*sizeof(double)); + buf2 = (double*) malloc((double) rows*rows*sizeof(double)); + LSCALE = (double*) malloc((double) rows*sizeof(double)); + RSCALE = (double*) malloc((double) rows*sizeof(double)); + LWORK = (double*) malloc((double) 6*rows*sizeof(double)); + + /*copy input to temp buf as lapack function modifies input*/ + memcpy(buf1,in1,rows*rows*sizeof(double)); + memcpy(buf2,in2,rows*rows*sizeof(double)); + + dggbal_(&JOB,&rows,buf1,&rows,buf2,&rows,&ILO,&IHI,LSCALE,RSCALE, \ + LWORK,INFO); + deyea(out3,rows,rows); + deyea(out4,rows,rows); + + dgebak_(&JOB,&LSIDE,&rows,&ILO,&IHI,LSCALE,&rows,out3,&rows,&INFO); + dgebak_(&JOB,&RSIDE,&rows,&ILO,&IHI,LSCALE,&rows,out4,&rows,&INFO); + + /*copy computed matrix to output*/ + memcpy(out1,buf1,rows*rows*sizeof(double)); + memcpy(out2,buf2,rows*rows*sizeof(double)); + + } + +}
\ No newline at end of file diff --git a/2.3-1/src/c/linearAlgebra/includes/balanc.h b/2.3-1/src/c/linearAlgebra/includes/balanc.h new file mode 100644 index 00000000..dcc66b28 --- /dev/null +++ b/2.3-1/src/c/linearAlgebra/includes/balanc.h @@ -0,0 +1,27 @@ + /* Copyright (C) 2017 - IIT Bombay - FOSSEE + + This file must be used under the terms of the CeCILL. + This source file is licensed as described in the file COPYING, which + you should have received as part of this distribution. The terms + are also available at + http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt + Author: Siddhesh Wani + Organization: FOSSEE, IIT Bombay + Email: toolbox@scilab.in + */ +#ifndef __BALANC_H__ +#define __BALANC_H__ + + +#ifdef __cplusplus +extern "C" { +#endif + +void dbalanca(double* in1, int rows, double* in2, double* out1, \ + double* out2, double* out3, double* out4); + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /*__BALANC_H__*/ diff --git a/2.3-1/src/c/linearAlgebra/includes/rcond.h b/2.3-1/src/c/linearAlgebra/includes/rcond.h new file mode 100644 index 00000000..4796f029 --- /dev/null +++ b/2.3-1/src/c/linearAlgebra/includes/rcond.h @@ -0,0 +1,26 @@ + /* Copyright (C) 2017 - IIT Bombay - FOSSEE + + This file must be used under the terms of the CeCILL. + This source file is licensed as described in the file COPYING, which + you should have received as part of this distribution. The terms + are also available at + http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt + Author: Siddhesh Wani + Organization: FOSSEE, IIT Bombay + Email: toolbox@scilab.in + */ +#ifndef __RCOND_H__ +#define __RCOND_H__ + + +#ifdef __cplusplus +extern "C" { +#endif + +double drconda(double* in1, int rows); + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /*__RCOND_H__*/ diff --git a/2.3-1/src/c/linearAlgebra/interfaces/int_balanc.h b/2.3-1/src/c/linearAlgebra/interfaces/int_balanc.h new file mode 100644 index 00000000..a16ba8c2 --- /dev/null +++ b/2.3-1/src/c/linearAlgebra/interfaces/int_balanc.h @@ -0,0 +1,29 @@ + /* Copyright (C) 2017 - IIT Bombay - FOSSEE + + This file must be used under the terms of the CeCILL. + This source file is licensed as described in the file COPYING, which + you should have received as part of this distribution. The terms + are also available at + http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt + Author: Siddhesh Wani + Organization: FOSSEE, IIT Bombay + Email: toolbox@scilab.in + */ +#ifndef __INT_BALANC_H__ +#define __INT_BALANC_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#define d2balancd2d2(in1,size1,out1,out2) dbalanca(in1,size1[0],NULL,out1, \ + out2,NULL,NULL) + +#define d2d2balancd2d2d2d2(in1,size1,in2,size2,out1,out2,out3,out4) \ + dbalanca(in1,size1[0],in2,out1,out2,out3,out4) + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /*__INT_BALANC_H__*/ diff --git a/2.3-1/src/c/linearAlgebra/interfaces/int_rcond.h b/2.3-1/src/c/linearAlgebra/interfaces/int_rcond.h new file mode 100644 index 00000000..6e6a4454 --- /dev/null +++ b/2.3-1/src/c/linearAlgebra/interfaces/int_rcond.h @@ -0,0 +1,25 @@ + /* Copyright (C) 2017 - IIT Bombay - FOSSEE + + This file must be used under the terms of the CeCILL. + This source file is licensed as described in the file COPYING, which + you should have received as part of this distribution. The terms + are also available at + http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt + Author: Siddhesh Wani + Organization: FOSSEE, IIT Bombay + Email: toolbox@scilab.in + */ +#ifndef __INT_RCOND_H__ +#define __INT_RCOND_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#define d2rcondd0(in1,size1) drconda(in1,size1[0]) + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /*__INT_RCOND_H__*/ diff --git a/2.3-1/src/c/linearAlgebra/rcond/drconda.c b/2.3-1/src/c/linearAlgebra/rcond/drconda.c new file mode 100644 index 00000000..2082e9de --- /dev/null +++ b/2.3-1/src/c/linearAlgebra/rcond/drconda.c @@ -0,0 +1,46 @@ +/* Copyright (C) 2017 - IIT Bombay - FOSSEE + + This file must be used under the terms of the CeCILL. + This source file is licensed as described in the file COPYING, which + you should have received as part of this distribution. The terms + are also available at + http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt + Author: Siddhesh Wani + Organization: FOSSEE, IIT Bombay + Email: toolbox@scilab.in + */ + +/*Funtion to find inverse condition number of square matrix*/ + +#include "lapack.h" +#include "stdlib.h" +#include "string.h" + +double drconda(double* in1, int rows) +{ + double *buf, *IPIV, *LDWORK, *LIWORK; + int INFO; + char one = '1'; + double ANORM; + double RCOND = 1; + + buf = (double*) malloc((double) rows*rows*sizeof(double)); + IPIV = (double*) malloc((double) rows*sizeof(double)); + LIWORK = (double*) malloc((double) rows*sizeof(double)); + LDWORK = (double*) malloc((double) 4*rows*sizeof(double)); + + /*Copy input in temp buf, as lapack modifies input*/ + memcpy(buf,in1,rows*rows*sizeof(double)); + + ANORM = dlange_(&one,&rows,&rows,buf,&rows,LDWORK); + + dgetrf_(&rows,&rows,buf,&rows,IPIV,&INFO); + + if(INFO == 0) + { + dgecon_(&one,&rows,buf,&rows,&ANORM,&RCOND,LDWORK,LIWORK,&INFO); + } + + return RCOND; + +}
\ No newline at end of file diff --git a/2.3-1/src/c/linearAlgebra/schur/dschura.c b/2.3-1/src/c/linearAlgebra/schur/dschura.c index 79c41976..802caa81 100644 --- a/2.3-1/src/c/linearAlgebra/schur/dschura.c +++ b/2.3-1/src/c/linearAlgebra/schur/dschura.c @@ -10,7 +10,7 @@ Email: toolbox@scilab.in */ -/*Fucntion to find schur decomposition of given square matrix */ +/*Funtion to find schur decomposition of given square matrix */ #include "schur.h" #include "lapack.h" #include "stdlib.h" |