summaryrefslogtreecommitdiff
path: root/src/c/matrixOperations/determ/zdeterma.c
diff options
context:
space:
mode:
authorSiddhesh Wani2015-05-25 14:46:31 +0530
committerSiddhesh Wani2015-05-25 14:46:31 +0530
commitdb464f35f5a10b58d9ed1085e0b462689adee583 (patch)
treede5cdbc71a54765d9fec33414630ae2c8904c9b8 /src/c/matrixOperations/determ/zdeterma.c
downloadScilab2C_fossee_old-db464f35f5a10b58d9ed1085e0b462689adee583.tar.gz
Scilab2C_fossee_old-db464f35f5a10b58d9ed1085e0b462689adee583.tar.bz2
Scilab2C_fossee_old-db464f35f5a10b58d9ed1085e0b462689adee583.zip
Original Version
Diffstat (limited to 'src/c/matrixOperations/determ/zdeterma.c')
-rw-r--r--src/c/matrixOperations/determ/zdeterma.c138
1 files changed, 138 insertions, 0 deletions
diff --git a/src/c/matrixOperations/determ/zdeterma.c b/src/c/matrixOperations/determ/zdeterma.c
new file mode 100644
index 0000000..ea7e98d
--- /dev/null
+++ b/src/c/matrixOperations/determ/zdeterma.c
@@ -0,0 +1,138 @@
+/*
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ * Copyright (C) 2008 - INRIA - Arnaud TORSET
+ *
+ * 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
+ *
+ */
+
+#include <stdlib.h>
+#ifndef WITHOUT_LAPACK
+#include "lapack.h"
+#else
+#include "division.h"
+#endif
+#include "determ.h"
+#include "multiplication.h"
+#include "subtraction.h"
+#include "addition.h"
+
+
+doubleComplex zdeterma(doubleComplex * in, int size){
+#ifndef WITHOUT_LAPACK
+ doubleComplex tmp1,tmp2,out;
+ int i=0,info=0;
+ doubleComplex *inCopy;
+ int* vectPivot;
+
+ switch(size){
+ case 2 : out = zdiffs(zmuls(in[0],in[3]),zmuls(in[1],in[2]));
+ break;
+ case 3 : /*regle de Sarrus*/
+ out=DoubleComplex(0,0);
+ /*Addition Part*/
+ tmp1 = zmuls(in[0],in[4]);
+ tmp2 = zmuls(tmp1,in[8]);
+ out = zadds(out,tmp2);
+ tmp1 = zmuls(in[1],in[5]);
+ tmp2 = zmuls(tmp1,in[6]);
+ out = zadds(out,tmp2);
+ tmp1 = zmuls(in[2],in[3]);
+ tmp2 = zmuls(tmp1,in[7]);
+ out = zadds(out,tmp2);
+ /*Subtraction Part*/
+ tmp1 = zmuls(in[0],in[5]);
+ tmp2 = zmuls(tmp1,in[7]);
+ out = zdiffs(out,tmp2);
+ tmp1 = zmuls(in[1],in[3]);
+ tmp2 = zmuls(tmp1,in[8]);
+ out = zdiffs(out,tmp2);
+ tmp1 = zmuls(in[2],in[4]);
+ tmp2 = zmuls(tmp1,in[6]);
+ out = zdiffs(out,tmp2);
+ break;
+
+ default :
+ /*Allocate inCopy and Copy in in inCopy*/
+ inCopy=(doubleComplex*)malloc((unsigned int)(size*size)*sizeof(doubleComplex));
+ for (i=0;i<size*size;i++) inCopy[i]=in[i];
+
+ /*Calculation of determinant*/
+ vectPivot = (int*)malloc((unsigned int)size*sizeof(int));
+ zgetrf_ ( &size, &size, inCopy, &size, vectPivot, &info);
+
+ out=DoubleComplex(1,0);
+ for (i=0;i<size;i++){
+ if (vectPivot[i]!=i+1) out=DoubleComplex(-zreals(out),-zimags(out));
+ out=zmuls(inCopy[i*(size+1)],out);
+ }
+ free(vectPivot);
+ free(inCopy);
+ break;
+ }
+
+#else
+ int i=0,j=0,k=0;
+ doubleComplex *inCopy;
+ doubleComplex tmp1,tmp2;
+ doubleComplex pivot;
+ doubleComplex out;
+
+
+ switch(size){
+ case 2 : out = zdiffs(zmuls(in[0],in[3]),zmuls(in[1],in[2]));
+ break;
+ case 3 : /*regle de Sarrus*/
+ out=DoubleComplex(0,0);
+ /*Addition Part*/
+ tmp1 = zmuls(in[0],in[4]);
+ tmp2 = zmuls(tmp1,in[8]);
+ out = zadds(out,tmp2);
+ tmp1 = zmuls(in[1],in[5]);
+ tmp2 = zmuls(tmp1,in[6]);
+ out = zadds(out,tmp2);
+ tmp1 = zmuls(in[2],in[3]);
+ tmp2 = zmuls(tmp1,in[7]);
+ out = zadds(out,tmp2);
+ /*Subtraction Part*/
+ tmp1 = zmuls(in[0],in[5]);
+ tmp2 = zmuls(tmp1,in[7]);
+ out = zdiffs(out,tmp2);
+ tmp1 = zmuls(in[1],in[3]);
+ tmp2 = zmuls(tmp1,in[8]);
+ out = zdiffs(out,tmp2);
+ tmp1 = zmuls(in[2],in[4]);
+ tmp2 = zmuls(tmp1,in[6]);
+ out = zdiffs(out,tmp2);
+ break;
+
+ default :
+ /*Copy the input matrix*/
+ inCopy=malloc((unsigned int)(size*size)*sizeof(doubleComplex));
+ for (i=0;i<size*size;i++) inCopy[i]=in[i];
+
+ for (i=0;i<size;i++){
+ for (j=i+1;j<size;j++){
+ pivot = zrdivs(inCopy[i*size+j],inCopy[i*size+i]);
+ for (k=0;k<size-i;k++){
+ inCopy[i*size+j+k*size]=zdiffs(inCopy[i*size+j+k*size],zmuls(pivot,inCopy[i*size+i+k*size]));
+ }
+ }
+ }
+ out=DoubleComplex(1,0);
+ for (i=0;i<size;i++){
+ out = zmuls(out,inCopy[i*size+i]);
+ }
+ free(inCopy);
+ break;
+ }
+#endif
+ return out;
+
+}
+
+