diff options
author | siddhu8990 | 2017-04-13 10:42:02 +0530 |
---|---|---|
committer | siddhu8990 | 2017-04-13 10:42:02 +0530 |
commit | aceeb1fe05a8ff6c126ea9ba166a19249488dbd1 (patch) | |
tree | 705b22f253408d29d073284477221a8af64dda3a /src | |
parent | e7dba33a909e158dffc6ddb3361df10d427db631 (diff) | |
download | Scilab2C_fossee_old-aceeb1fe05a8ff6c126ea9ba166a19249488dbd1.tar.gz Scilab2C_fossee_old-aceeb1fe05a8ff6c126ea9ba166a19249488dbd1.tar.bz2 Scilab2C_fossee_old-aceeb1fe05a8ff6c126ea9ba166a19249488dbd1.zip |
Functions added - balance,rcond,obscont
Diffstat (limited to 'src')
-rw-r--r-- | src/c/CACSD/includes/obscont.h | 28 | ||||
-rw-r--r-- | src/c/CACSD/interfaces/int_obscont.h | 29 | ||||
-rw-r--r-- | src/c/CACSD/obscont/dobsconta.c | 284 | ||||
-rw-r--r-- | src/c/hardware/rasberrypi/gpio/u8RPIDigitalSetups.c | 7 | ||||
-rw-r--r-- | src/c/hardware/rasberrypi/includes/RPIPeripheralSerial.h | 4 | ||||
-rw-r--r-- | src/c/hardware/rasberrypi/serial/u16RPISerialSetups.c (renamed from src/c/hardware/rasberrypi/serial/u8RPISerialSetups.c) | 0 | ||||
-rw-r--r-- | src/c/linearAlgebra/balanc/dbalanca.c | 75 | ||||
-rw-r--r-- | src/c/linearAlgebra/includes/balanc.h | 27 | ||||
-rw-r--r-- | src/c/linearAlgebra/includes/rcond.h | 26 | ||||
-rw-r--r-- | src/c/linearAlgebra/interfaces/int_balanc.h | 29 | ||||
-rw-r--r-- | src/c/linearAlgebra/interfaces/int_rcond.h | 25 | ||||
-rw-r--r-- | src/c/linearAlgebra/rcond/drconda.c | 46 | ||||
-rw-r--r-- | src/c/linearAlgebra/schur/dschura.c | 2 |
13 files changed, 576 insertions, 6 deletions
diff --git a/src/c/CACSD/includes/obscont.h b/src/c/CACSD/includes/obscont.h new file mode 100644 index 0000000..f316adb --- /dev/null +++ b/src/c/CACSD/includes/obscont.h @@ -0,0 +1,28 @@ + /* 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 __OBSCONT_H__ +#define __OBSCONT_H__ + + +#ifdef __cplusplus +extern "C" { +#endif + +void dobsconta(double* sys, int sys_rows, int sys_cols, double* Kc, double* Kf, \ + double *K, double *r); + + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /*__OBSCONT_H__*/ diff --git a/src/c/CACSD/interfaces/int_obscont.h b/src/c/CACSD/interfaces/int_obscont.h new file mode 100644 index 0000000..fd3a823 --- /dev/null +++ b/src/c/CACSD/interfaces/int_obscont.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_OBSCONT_H__ +#define __INT_OBSCONT_H__ + + #ifdef __cplusplus + extern "C" { + #endif + +#define ss2d2d2obscontd2(in1,size1,in2,size2,in3,size3,out) \ + dobsconta(in1,size1[0],size1[1],in2,in3,out,NULL) + +#define ss2d2d2obscontd2d2(in1,size1,in2,size2,in3,size3,out1,out2) \ + dobsconta(in1,size1[0],size1[1],in2,in3,out1,out2) + + #ifdef __cplusplus + } /* extern "C" */ + #endif + +#endif /*__INT_OBSCONT_H__*/ diff --git a/src/c/CACSD/obscont/dobsconta.c b/src/c/CACSD/obscont/dobsconta.c new file mode 100644 index 0000000..7e29752 --- /dev/null +++ b/src/c/CACSD/obscont/dobsconta.c @@ -0,0 +1,284 @@ +/* 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 +*/ + +/*Function for calculating observer controller. + Refer 'obscont.sci' in scilab source.*/ + +#include <stdlib.h> +#include "matrixMultiplication.h" +#include "addition.h" + +void dobsconta(double* sys, int sys_rows, int sys_cols, double* Kc, double* Kf, \ + double *K, double *r) +{ + int no_of_states, no_of_inputs, no_of_outputs, dom = 1; + int row,col; + no_of_states = sys[sys_rows*(sys_cols-1)]; + no_of_inputs = sys[sys_rows*(sys_cols-1) + 1]; + no_of_outputs = sys_rows - no_of_states; + + int no_of_cols; + int no_of_rows; + + double *A, *B, *C, *D; + double *BKc, *KfC, *KfD,*DKc; + double *buf, *buf1, *buf2; + + A = (double*) malloc (no_of_states*no_of_states*sizeof(double)); + B = (double*) malloc (no_of_states*no_of_inputs*sizeof(double)); + C = (double*) malloc (no_of_states*no_of_outputs*sizeof(double)); + D = (double*) malloc (no_of_inputs*no_of_outputs*sizeof(double)); + + BKc = (double*) malloc (no_of_states*no_of_states*sizeof(double)); + KfC = (double*) malloc (no_of_states*no_of_states*sizeof(double)); + KfD = (double*) malloc (no_of_states*no_of_inputs*sizeof(double)); + DKc = (double*) malloc (no_of_outputs*no_of_states*sizeof(double)); + buf = (double*) malloc (no_of_states*no_of_states*sizeof(double)); + buf1 = (double*) malloc (no_of_states*no_of_inputs*sizeof(double)); + buf2 = (double*) malloc (no_of_outputs*no_of_states*sizeof(double)); + + /*Get A from system matrix*/ + for(col = 0; col < no_of_states; col++) + { + for(row = 0; row < no_of_states; row++) + { + A[col*no_of_states + row] = sys[col*sys_rows + row]; + } + } + + /*Get matrix B from system matrix*/ + for(col=0; col < no_of_inputs; col++) + { + for(row = 0; row < no_of_states; row++) + { + B[col * no_of_states + row] = \ + sys[col * sys_rows + no_of_states*sys_rows + row]; + } + } + + /*Get matrix C from system matrix*/ + for(col=0; col < no_of_states; col++) + { + for(row = 0; row < no_of_outputs; row++) + { + C[col * no_of_outputs + row] = \ + sys[no_of_states + (col*sys_rows) + row]; + } + } + + /*Get matrix D from system matrix*/ + for(col=0; col < no_of_inputs; col++) + { + for(row = 0; row < no_of_outputs; row++) + { + D[col * no_of_outputs + row] = \ + sys[(no_of_states+col)*sys_rows + no_of_states + row]; + } + } + + dom = sys[(sys_rows*(sys_cols-2)) + no_of_states]; + + dmulma(B,no_of_states,no_of_inputs,Kc,no_of_inputs,no_of_states,BKc); + dmulma(Kf,no_of_states,no_of_outputs,C,no_of_outputs,no_of_states,KfC); + dmulma(Kf,no_of_states,no_of_outputs,D,no_of_outputs,no_of_inputs,KfD); + + /*Variables are reused to save memory*/ + /*A+BKc*/ + dadda(A,no_of_states*no_of_states,BKc,no_of_states*no_of_states,buf); + /*A+BKc+KfC*/ + dadda(KfC,no_of_states*no_of_states,buf,no_of_states*no_of_states,A); + /*KfDKc*/ + dmulma(KfD,no_of_states,no_of_inputs,Kc,no_of_inputs,no_of_states,BKc); + /*A+BKc+KfC+KfDKc*/ + dadda(A,no_of_states*no_of_states,BKc,no_of_states*no_of_states,buf); + + /*Dimensions of K*/ + no_of_cols = no_of_states + no_of_inputs + 2; + no_of_rows = no_of_states + no_of_outputs; + + if(r == NULL) + { + /*Dimensions of K*/ + no_of_cols = no_of_states + no_of_outputs + 2; + no_of_rows = no_of_states + no_of_inputs; + + for(col = 0; col < no_of_states; col++) + { + for(row = 0; row < no_of_states; row++) + { + K[col*no_of_rows + row] = buf[col*no_of_states + row]; + } + + } + + /*Copy matrix -Kf in out matrix*/ + for(col=0; col < no_of_outputs; col++) + { + for(row = 0; row < no_of_states; row++) + { + K[col * no_of_rows + no_of_states*no_of_rows + row] \ + = -1.0*Kf[col * no_of_states + row]; + } + } + + /*Copy matrix Kc in out matrix*/ + for(col=0; col < no_of_states; col++) + { + for(row = 0; row < no_of_inputs; row++) + { + K[no_of_states + (col*no_of_rows) + row] = Kc[col * no_of_inputs + row]; + } + } + + K[(no_of_rows*(no_of_cols-2)) + no_of_states] = dom; + /*Insert no of states and inputs in last column*/ + K[(no_of_rows*(no_of_cols-1))] = no_of_states; + K[(no_of_rows*(no_of_cols-1))+1] = no_of_outputs; + /*For K, no_of_outputs is no of inputs*/ + + } + else + { + /*Dimensions of K*/ + no_of_cols = no_of_states + no_of_inputs + no_of_outputs + 2; + no_of_rows = no_of_states + no_of_outputs + no_of_inputs; + + r[0] = no_of_outputs; + r[1] = no_of_inputs; + + for(col = 0; col < no_of_states; col++) + { + for(row = 0; row < no_of_states; row++) + { + K[col*no_of_rows + row] = buf[col*no_of_states + row]; + } + + } + + /*Copy matrix -Kf in out matrix*/ + for(col=0; col < no_of_outputs; col++) + { + for(row = 0; row < no_of_states; row++) + { + K[col * no_of_rows + no_of_states*no_of_rows + row] \ + = -1.0*Kf[col * no_of_states + row]; + } + } + + /*B+Kf*D*/ + dadda(B,no_of_states*no_of_inputs,KfD,no_of_states*no_of_inputs,buf1); + + /*Copy matrix (B+KfD) in out matrix*/ + for(col=0; col < no_of_inputs; col++) + { + for(row = 0; row < no_of_states; row++) + { + K[col * no_of_rows + (no_of_states+no_of_outputs)*no_of_rows \ + + row] = buf1[col * no_of_states + row]; + } + } + + /*DKc*/ + dmulma(D,no_of_outputs,no_of_inputs,Kc,no_of_inputs,no_of_states,DKc); + /*C+DKc*/ + dadda(C,no_of_outputs*no_of_states,DKc,no_of_outputs*no_of_states,buf2); + + /*Copy matrix Kc in out matrix*/ + for(col=0; col < no_of_states; col++) + { + for(row = 0; row < no_of_inputs; row++) + { + K[no_of_states + (col*no_of_rows) + row] \ + = Kc[col * no_of_inputs + row]; + } + } + + /*Copy -(C+DKc) in out matrix*/ + for(col=0; col < no_of_states; col++) + { + for(row = 0; row < no_of_outputs; row++) + { + K[(no_of_states+no_of_inputs) + (col*no_of_rows) + row] \ + = -1.0*buf2[col * no_of_outputs + row]; + } + } + + /*Block 22 for K*/ + for(col=0; col < no_of_outputs; col++) + { + for(row = 0; row < no_of_inputs; row++) + { + K[no_of_states + (col*no_of_rows) + no_of_states*no_of_rows \ + + row] = 0; + } + } + + for(col=0; col < no_of_inputs; col++) + { + for(row = 0; row < no_of_inputs; row++) + { + if(row == col) + K[no_of_states + (col*no_of_rows) + \ + (no_of_states+no_of_outputs)*no_of_rows + row] = 1; + else + K[no_of_states + (col*no_of_rows) + \ + (no_of_states+no_of_outputs)*no_of_rows + row] = 0; + } + } + + for(col=0; col < no_of_outputs; col++) + { + for(row = 0; row < no_of_outputs; row++) + { + if(row == col) + K[no_of_states + no_of_inputs + (col*no_of_rows) + \ + no_of_states*no_of_rows + row] = 1; + else + K[no_of_states + no_of_inputs + (col*no_of_rows) + \ + no_of_states*no_of_rows + row] = 0; + } + } + + + for(col=0; col < no_of_inputs; col++) + { + for(row = 0; row < no_of_outputs; row++) + { + K[no_of_states + no_of_inputs + (col*no_of_rows) + \ + (no_of_states+no_of_outputs)*no_of_rows + row] \ + = -1.0*D[col*no_of_inputs + row]; + } + } + + + K[(no_of_rows*(no_of_cols-2))+ no_of_states] = dom; + /*Insert no of states and inputs in last column*/ + K[(no_of_rows*(no_of_cols-1))] = no_of_states; + K[(no_of_rows*(no_of_cols-1))+1] = no_of_outputs + no_of_inputs; + /*For K, (no_of_outputs+no_of_inputs) is no of inputs*/ + + + } + + + free(A); + free(B); + free(C); + free(D); + free(BKc); + free(KfC); + free(KfD); + free(DKc); + free(buf); + free(buf1); + free(buf2); +} diff --git a/src/c/hardware/rasberrypi/gpio/u8RPIDigitalSetups.c b/src/c/hardware/rasberrypi/gpio/u8RPIDigitalSetups.c index fa86025..f5fefe0 100644 --- a/src/c/hardware/rasberrypi/gpio/u8RPIDigitalSetups.c +++ b/src/c/hardware/rasberrypi/gpio/u8RPIDigitalSetups.c @@ -21,9 +21,10 @@ /*This array maps pin numbers on RPi board, with pin numbers corrsponding to WiringPi library*/ -int phy_pin[] = {17, 17, 8, 17, 9, 17, 7, 15, 17, 16, /*Pin 1 to 10*/ - 0, 1, 2, 17, 3, 4, 17, 5, 12, 17, /*Pin 11 to 20*/ - 13, 6, 14, 10, 17, 11 }; /*Pin 21 to 26*/ +int phy_pin[] = {17, 17, 8, 17, 9, 17, 7, 15, 17, 16, /*Pin 1 to 10*/ + 0, 1, 2, 17, 3, 4, 17, 5, 12, 17, /*Pin 11 to 20*/ + 13, 6, 14, 10, 17, 11, 30, 31, 21, 17, /*Pin 21 to 30*/ + 22, 26, 23, 17, 24, 27, 25, 28, 17, 29 }; /*Pin 31 to 40*/ /*pin is reduced by one as arrayiindex starts from 0 and pin no starts from 1*/ void u8RPIDigitalSetups(uint8 pin, uint8 direction) diff --git a/src/c/hardware/rasberrypi/includes/RPIPeripheralSerial.h b/src/c/hardware/rasberrypi/includes/RPIPeripheralSerial.h index 76a229e..14df95b 100644 --- a/src/c/hardware/rasberrypi/includes/RPIPeripheralSerial.h +++ b/src/c/hardware/rasberrypi/includes/RPIPeripheralSerial.h @@ -29,13 +29,13 @@ void u16RPISerialSendDatas(int fd, uint16 data); void i16RPISerialSendDatas(int fd, int16 data); void sRPISerialSendDatas(int fd, float data); void dRPISerialSendDatas(int fd, double data); -void u8RPISerialSendDataa(int fd, void* data, int size); +void u8RPISerialSendDataa(int fd, uint8* data, int size); void i8RPISerialSendDataa(int fd, int8* data, int size); void u16RPISerialSendDataa(int fd, uint16* data, int size); void i16RPISerialSendDataa(int fd, int16* data, int size); void sRPISerialSendDataa(int fd, float* data, int size); void dRPISerialSendDataa(int fd, double* data, int size); -void gRPISerialSendDatas(int fd, void* data, int size); +void gRPISerialSendDatas(int fd, uint8* data, int size); int16 i16RPISerialDataAvails(int fd); int16 i16RPISerialGetChars(int fd); diff --git a/src/c/hardware/rasberrypi/serial/u8RPISerialSetups.c b/src/c/hardware/rasberrypi/serial/u16RPISerialSetups.c index cde4cba..cde4cba 100644 --- a/src/c/hardware/rasberrypi/serial/u8RPISerialSetups.c +++ b/src/c/hardware/rasberrypi/serial/u16RPISerialSetups.c diff --git a/src/c/linearAlgebra/balanc/dbalanca.c b/src/c/linearAlgebra/balanc/dbalanca.c new file mode 100644 index 0000000..558c614 --- /dev/null +++ b/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/src/c/linearAlgebra/includes/balanc.h b/src/c/linearAlgebra/includes/balanc.h new file mode 100644 index 0000000..dcc66b2 --- /dev/null +++ b/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/src/c/linearAlgebra/includes/rcond.h b/src/c/linearAlgebra/includes/rcond.h new file mode 100644 index 0000000..4796f02 --- /dev/null +++ b/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/src/c/linearAlgebra/interfaces/int_balanc.h b/src/c/linearAlgebra/interfaces/int_balanc.h new file mode 100644 index 0000000..a16ba8c --- /dev/null +++ b/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/src/c/linearAlgebra/interfaces/int_rcond.h b/src/c/linearAlgebra/interfaces/int_rcond.h new file mode 100644 index 0000000..6e6a445 --- /dev/null +++ b/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/src/c/linearAlgebra/rcond/drconda.c b/src/c/linearAlgebra/rcond/drconda.c new file mode 100644 index 0000000..2082e9d --- /dev/null +++ b/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/src/c/linearAlgebra/schur/dschura.c b/src/c/linearAlgebra/schur/dschura.c index 79c4197..802caa8 100644 --- a/src/c/linearAlgebra/schur/dschura.c +++ b/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" |