diff options
author | Brijeshcr | 2017-07-07 17:09:19 +0530 |
---|---|---|
committer | Brijeshcr | 2017-07-07 17:09:19 +0530 |
commit | 282cbe9542cddac862b88d3431a18db9df781ba7 (patch) | |
tree | 2f3f8ed5c72b77cfec057c1e1511ecd0a9467d54 /2.3-1/src/c/linearAlgebra/givens/dgivensa.c | |
parent | 46da80312c4bc66bb5f16044c5c5597ac259d419 (diff) | |
parent | 8106d4ce6960cfd63c3a42171fdf5d52e46ccb06 (diff) | |
download | Scilab2C-282cbe9542cddac862b88d3431a18db9df781ba7.tar.gz Scilab2C-282cbe9542cddac862b88d3431a18db9df781ba7.tar.bz2 Scilab2C-282cbe9542cddac862b88d3431a18db9df781ba7.zip |
Linear Algebra changes by Sandeep
Diffstat (limited to '2.3-1/src/c/linearAlgebra/givens/dgivensa.c')
-rw-r--r-- | 2.3-1/src/c/linearAlgebra/givens/dgivensa.c | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/2.3-1/src/c/linearAlgebra/givens/dgivensa.c b/2.3-1/src/c/linearAlgebra/givens/dgivensa.c new file mode 100644 index 00000000..9bf0637b --- /dev/null +++ b/2.3-1/src/c/linearAlgebra/givens/dgivensa.c @@ -0,0 +1,76 @@ +/* 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 + */ + +/* GIVENS scilab function + Syntax : u=givens(xy) + u=givens(x,y) + xy = [x;y], u=givens(xy) + returns a 2*2 matrix u such that u*xy=[r;0]. + c is equal to u*xy + givens(x,y)=givens([x;y]) +*/ + +#include "givens.h" +#include <stdio.h> +#include <math.h> +#include "norm.h" + +/* All variable names are according to scilab code */ + +void dgivensa(int ninp,double *inp1,int row,int col,double *inp2,int row1,int col1,int nout,double *out1,double *out2){ + double *x; + double r; + x = (double *)malloc((double)2*sizeof(double)); + if(ninp == 2){ + if(row != 1 || col != 1 || row1 != 1 || col1 != 1){ + printf("Wrong size for input argument: A column vector expected.\n"); + return; + } + *(x) = *(inp1); + *(x+1) = *(inp2); + } + else{ + //printf("(%d %d)",row,col); + if(row != 2 || col != 1){ + printf("Wrong size for input argument: A column vector expected.\n"); + return; + } + //printf("(%lf %lf)",inp1[0],inp1[1]); + x[0] = inp1[0]; + x[1] = inp1[1]; + } + if(*(x+1) != 0){ + //printf("(%lf %lf)",x[0],x[1]); + /*Norm of type 2 - find the maximum singular value*/ + r = dnorma(x,2,1,2); + //printf("%lf \n",r); + *(out1) = (*(x))/r; + *(out1+1) = -(*(x+1))/r; + *(out1+2) = (*(x+1))/r; + *(out1+3) = (*(x))/r; + if(nout == 2){ + *(out2) = r; + *(out2+1) = 0; + } + + } + else{ + *(out1) = 1; + *(out1+1) = 0; + *(out1+2) = 1; + *(out1+3) = 0; + if(nout == 2){ + *(out2) = *(x); + *(out2+1) = *(x+1); + } + } +} |