LAPACK 3.12.1
LAPACK: Linear Algebra PACKage
Loading...
Searching...
No Matches
dlarfg.f
Go to the documentation of this file.
1*> \brief \b DLARFG generates an elementary reflector (Householder matrix).
2*
3* =========== DOCUMENTATION ===========
4*
5* Online html documentation available at
6* http://www.netlib.org/lapack/explore-html/
7*
8*> Download DLARFG + dependencies
9*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/dlarfg.f">
10*> [TGZ]</a>
11*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/dlarfg.f">
12*> [ZIP]</a>
13*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/dlarfg.f">
14*> [TXT]</a>
15*
16* Definition:
17* ===========
18*
19* SUBROUTINE DLARFG( N, ALPHA, X, INCX, TAU )
20*
21* .. Scalar Arguments ..
22* INTEGER INCX, N
23* DOUBLE PRECISION ALPHA, TAU
24* ..
25* .. Array Arguments ..
26* DOUBLE PRECISION X( * )
27* ..
28*
29*
30*> \par Purpose:
31* =============
32*>
33*> \verbatim
34*>
35*> DLARFG generates a real elementary reflector H of order n, such
36*> that
37*>
38*> H * ( alpha ) = ( beta ), H**T * H = I.
39*> ( x ) ( 0 )
40*>
41*> where alpha and beta are scalars, and x is an (n-1)-element real
42*> vector. H is represented in the form
43*>
44*> H = I - tau * ( 1 ) * ( 1 v**T ) ,
45*> ( v )
46*>
47*> where tau is a real scalar and v is a real (n-1)-element
48*> vector.
49*>
50*> If the elements of x are all zero, then tau = 0 and H is taken to be
51*> the unit matrix.
52*>
53*> Otherwise 1 <= tau <= 2.
54*> \endverbatim
55*
56* Arguments:
57* ==========
58*
59*> \param[in] N
60*> \verbatim
61*> N is INTEGER
62*> The order of the elementary reflector.
63*> \endverbatim
64*>
65*> \param[in,out] ALPHA
66*> \verbatim
67*> ALPHA is DOUBLE PRECISION
68*> On entry, the value alpha.
69*> On exit, it is overwritten with the value beta.
70*> \endverbatim
71*>
72*> \param[in,out] X
73*> \verbatim
74*> X is DOUBLE PRECISION array, dimension
75*> (1+(N-2)*abs(INCX))
76*> On entry, the vector x.
77*> On exit, it is overwritten with the vector v.
78*> \endverbatim
79*>
80*> \param[in] INCX
81*> \verbatim
82*> INCX is INTEGER
83*> The increment between elements of X. INCX > 0.
84*> \endverbatim
85*>
86*> \param[out] TAU
87*> \verbatim
88*> TAU is DOUBLE PRECISION
89*> The value tau.
90*> \endverbatim
91*
92* Authors:
93* ========
94*
95*> \author Univ. of Tennessee
96*> \author Univ. of California Berkeley
97*> \author Univ. of Colorado Denver
98*> \author NAG Ltd.
99*
100*> \ingroup larfg
101*
102* =====================================================================
103 SUBROUTINE dlarfg( N, ALPHA, X, INCX, TAU )
104*
105* -- LAPACK auxiliary routine --
106* -- LAPACK is a software package provided by Univ. of Tennessee, --
107* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
108*
109* .. Scalar Arguments ..
110 INTEGER INCX, N
111 DOUBLE PRECISION ALPHA, TAU
112* ..
113* .. Array Arguments ..
114 DOUBLE PRECISION X( * )
115* ..
116*
117* =====================================================================
118*
119* .. Parameters ..
120 DOUBLE PRECISION ONE, ZERO
121 parameter( one = 1.0d+0, zero = 0.0d+0 )
122* ..
123* .. Local Scalars ..
124 INTEGER J, KNT
125 DOUBLE PRECISION BETA, RSAFMN, SAFMIN, XNORM
126* ..
127* .. External Functions ..
128 DOUBLE PRECISION DLAMCH, DLAPY2, DNRM2
129 EXTERNAL dlamch, dlapy2, dnrm2
130* ..
131* .. Intrinsic Functions ..
132 INTRINSIC abs, sign
133* ..
134* .. External Subroutines ..
135 EXTERNAL dscal
136* ..
137* .. Executable Statements ..
138*
139 IF( n.LE.1 ) THEN
140 tau = zero
141 RETURN
142 END IF
143*
144 xnorm = dnrm2( n-1, x, incx )
145*
146 IF( xnorm.EQ.zero ) THEN
147*
148* H = I
149*
150 tau = zero
151 ELSE
152*
153* general case
154*
155 beta = -sign( dlapy2( alpha, xnorm ), alpha )
156 safmin = dlamch( 'S' ) / dlamch( 'E' )
157 knt = 0
158 IF( abs( beta ).LT.safmin ) THEN
159*
160* XNORM, BETA may be inaccurate; scale X and recompute them
161*
162 rsafmn = one / safmin
163 10 CONTINUE
164 knt = knt + 1
165 CALL dscal( n-1, rsafmn, x, incx )
166 beta = beta*rsafmn
167 alpha = alpha*rsafmn
168 IF( (abs( beta ).LT.safmin) .AND. (knt .LT. 20) )
169 $ GO TO 10
170*
171* New BETA is at most 1, at least SAFMIN
172*
173 xnorm = dnrm2( n-1, x, incx )
174 beta = -sign( dlapy2( alpha, xnorm ), alpha )
175 END IF
176 tau = ( beta-alpha ) / beta
177 CALL dscal( n-1, one / ( alpha-beta ), x, incx )
178*
179* If ALPHA is subnormal, it may lose relative accuracy
180*
181 DO 20 j = 1, knt
182 beta = beta*safmin
183 20 CONTINUE
184 alpha = beta
185 END IF
186*
187 RETURN
188*
189* End of DLARFG
190*
191 END
subroutine dlarfg(n, alpha, x, incx, tau)
DLARFG generates an elementary reflector (Householder matrix).
Definition dlarfg.f:104
subroutine dscal(n, da, dx, incx)
DSCAL
Definition dscal.f:79