00001 #include "cs.h"
00002 
00003 
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) ;          
00009     for (i = 1 ; i < n ; i++) sigma += x [i] * x [i] ;
00010     if (sigma == 0)
00011     {
00012         s = fabs (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) ;  
00019         x [0] = (x [0] <= 0) ? (x [0] - s) : (-sigma / (x [0] + s)) ;
00020         (*beta) = -1. / (s * x [0]) ;
00021     }
00022     return (s) ;
00023 }