diff options
author | ukashanoor | 2017-07-04 11:55:14 +0530 |
---|---|---|
committer | ukashanoor | 2017-07-04 11:55:14 +0530 |
commit | 771262669202239258b54394840cc75114f9cb2b (patch) | |
tree | 5f72862c9343dbe3cff3b790020a6c19c9e7038a /2.3-1/src/c/linearAlgebra/sva/dsvaa.c | |
parent | 2d8050d5bd74adc66b9a45f55078791a36434be8 (diff) | |
download | Scilab2C-771262669202239258b54394840cc75114f9cb2b.tar.gz Scilab2C-771262669202239258b54394840cc75114f9cb2b.tar.bz2 Scilab2C-771262669202239258b54394840cc75114f9cb2b.zip |
after debugging 1
Diffstat (limited to '2.3-1/src/c/linearAlgebra/sva/dsvaa.c')
-rw-r--r-- | 2.3-1/src/c/linearAlgebra/sva/dsvaa.c | 92 |
1 files changed, 92 insertions, 0 deletions
diff --git a/2.3-1/src/c/linearAlgebra/sva/dsvaa.c b/2.3-1/src/c/linearAlgebra/sva/dsvaa.c new file mode 100644 index 00000000..b7d07d8c --- /dev/null +++ b/2.3-1/src/c/linearAlgebra/sva/dsvaa.c @@ -0,0 +1,92 @@ +/* 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: Sandeep Gupta + Organization: FOSSEE, IIT Bombay + Email: toolbox@scilab.in + + */ +#include "sva.h" +#include "svd.h" +#include "lapack.h" +#include <stdio.h> +#include <stdlib.h> +#include "string.h" +#include "matrixTranspose.h" + +#define eps 2.22044604925e-16 + +void dsvaa(int ninp,double *in1,int row,int col,double in2,double *out1, \ + double *out2,double *out3){ + + double tol; + double rk=0; + int N=col,M=row; + if(row == 0 && col == 0) return; + int i,j; + int arow; /*Actual row of given matrix*/ + int acol; /*Actual col of given matrix*/ + + /* Calculation of svd of a given matrix */ + double *U,*S,*V; + U = (double *)malloc((double)row*min(row,col)*sizeof(double)); + S = (double *)malloc((double)min(row,col)*min(row,col)*sizeof(double)); + V = (double *)malloc((double)col*min(row,col)*sizeof(double)); + + dsvda(0,in1,M,N,1,3,U,S,V); + + if (ninp == 1){ /* [u,s,v] = sva(A) when input is only matrix */ + tol = max(row,col)*S[0]*eps; + rk = 0; + for(i=0;i<col;i++){ + if(S[i+i*row] > tol){ + rk+=1; + } + } + } + else{ /*[u,s,v] = sva(A,tol) when two input's are there */ + tol = in2; + if(tol > 1){ + rk = tol; + if(rk > min(row,col)){ + printf("ERROR: Wrong value for input argument !"); + out1 = NULL; + out2 = NULL; + out3 = NULL; + return; + } + } + else{ + rk = 0; + for(i=0;i<col;i++){ + if(S[i+i*row] > tol){ + rk+=1; + } + } + } + } + arow = M; + acol = min(M,N); + for(i=0;i<arow;i++){ + for(j=0;j<rk;j++){ + out1[i+j*row]=U[i+j*arow]; + } + } + arow = min(M,N); + for(i=0;i<rk;i++){ + for(j=0;j<rk;j++){ + out2[i+j*(int)rk] = S[i+j*arow]; + } + } + arow = N; + acol = min(M,N); + for(i=0;i<arow;i++){ + for(j=0;j<rk;j++){ + out3[i+j*arow] = V[i+j*arow]; + } + } +} |