cs_house.c
Go to the documentation of this file.
00001 #include "cs.h"
00002 /* create a Householder reflection [v,beta,s]=house(x), overwrite x with v,
00003  * where (I-beta*v*v')*x = s*e1.  See Algo 5.1.1, Golub & Van Loan, 3rd ed. */
00004 double cs_house (double *x, double *beta, int n)
00005 {
00006     double s, sigma = 0 ;
00007     int i ;
00008     if (!x || !beta) return (-1) ;          /* check inputs */
00009     for (i = 1 ; i < n ; i++) sigma += x [i] * x [i] ;
00010     if (sigma == 0)
00011     {
00012         s = fabs (x [0]) ;                  /* s = |x(0)| */
00013         (*beta) = (x [0] <= 0) ? 2 : 0 ;
00014         x [0] = 1 ;
00015     }
00016     else
00017     {
00018         s = sqrt (x [0] * x [0] + sigma) ;  /* s = norm (x) */
00019         x [0] = (x [0] <= 0) ? (x [0] - s) : (-sigma / (x [0] + s)) ;
00020         (*beta) = -1. / (s * x [0]) ;
00021     }
00022     return (s) ;
00023 }


re_vision
Author(s): Dorian Galvez-Lopez
autogenerated on Sun Jan 5 2014 11:30:59