snrm2.f.html
来自「famous linear algebra library (LAPACK) p」· HTML 代码 · 共 89 行
HTML
89 行
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>snrm2.f</title>
<meta name="generator" content="emacs 21.3.1; htmlfontify 0.20">
<style type="text/css"><!--
body { background: rgb(255, 255, 255); color: rgb(0, 0, 0); font-style: normal; font-weight: 500; font-stretch: normal; font-family: adobe-courier; font-size: 11pt; text-decoration: none; }
span.default { background: rgb(255, 255, 255); color: rgb(0, 0, 0); font-style: normal; font-weight: 500; font-stretch: normal; font-family: adobe-courier; font-size: 11pt; text-decoration: none; }
span.default a { background: rgb(255, 255, 255); color: rgb(0, 0, 0); font-style: normal; font-weight: 500; font-stretch: normal; font-family: adobe-courier; font-size: 11pt; text-decoration: underline; }
span.comment { color: rgb(178, 34, 34); background: rgb(255, 255, 255); font-style: normal; font-weight: 500; font-stretch: normal; font-family: adobe-courier; font-size: 11pt; text-decoration: none; }
span.comment a { color: rgb(178, 34, 34); background: rgb(255, 255, 255); font-style: normal; font-weight: 500; font-stretch: normal; font-family: adobe-courier; font-size: 11pt; text-decoration: underline; }
--></style>
</head>
<body>
<pre>
REAL FUNCTION <a name="SNRM2.1"></a><a href="snrm2.f.html#SNRM2.1">SNRM2</a>(N,X,INCX)
<span class="comment">*</span><span class="comment"> .. Scalar Arguments ..
</span> INTEGER INCX,N
<span class="comment">*</span><span class="comment"> ..
</span><span class="comment">*</span><span class="comment"> .. Array Arguments ..
</span> REAL X(*)
<span class="comment">*</span><span class="comment"> ..
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment"> Purpose
</span><span class="comment">*</span><span class="comment"> =======
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment"> <a name="SNRM2.12"></a><a href="snrm2.f.html#SNRM2.1">SNRM2</a> returns the euclidean norm of a vector via the function
</span><span class="comment">*</span><span class="comment"> name, so that
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment"> <a name="SNRM2.15"></a><a href="snrm2.f.html#SNRM2.1">SNRM2</a> := sqrt( x'*x ).
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment"> Further Details
</span><span class="comment">*</span><span class="comment"> ===============
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment"> -- This version written on 25-October-1982.
</span><span class="comment">*</span><span class="comment"> Modified on 14-October-1993 to inline the call to <a name="SLASSQ.21"></a><a href="slassq.f.html#SLASSQ.1">SLASSQ</a>.
</span><span class="comment">*</span><span class="comment"> Sven Hammarling, Nag Ltd.
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment"> .. Parameters ..
</span> REAL ONE,ZERO
PARAMETER (ONE=1.0E+0,ZERO=0.0E+0)
<span class="comment">*</span><span class="comment"> ..
</span><span class="comment">*</span><span class="comment"> .. Local Scalars ..
</span> REAL ABSXI,NORM,SCALE,SSQ
INTEGER IX
<span class="comment">*</span><span class="comment"> ..
</span><span class="comment">*</span><span class="comment"> .. Intrinsic Functions ..
</span> INTRINSIC ABS,SQRT
<span class="comment">*</span><span class="comment"> ..
</span> IF (N.LT.1 .OR. INCX.LT.1) THEN
NORM = ZERO
ELSE IF (N.EQ.1) THEN
NORM = ABS(X(1))
ELSE
SCALE = ZERO
SSQ = ONE
<span class="comment">*</span><span class="comment"> The following loop is equivalent to this call to the LAPACK
</span><span class="comment">*</span><span class="comment"> auxiliary routine:
</span><span class="comment">*</span><span class="comment"> CALL <a name="SLASSQ.45"></a><a href="slassq.f.html#SLASSQ.1">SLASSQ</a>( N, X, INCX, SCALE, SSQ )
</span><span class="comment">*</span><span class="comment">
</span> DO 10 IX = 1,1 + (N-1)*INCX,INCX
IF (X(IX).NE.ZERO) THEN
ABSXI = ABS(X(IX))
IF (SCALE.LT.ABSXI) THEN
SSQ = ONE + SSQ* (SCALE/ABSXI)**2
SCALE = ABSXI
ELSE
SSQ = SSQ + (ABSXI/SCALE)**2
END IF
END IF
10 CONTINUE
NORM = SCALE*SQRT(SSQ)
END IF
<span class="comment">*</span><span class="comment">
</span> <a name="SNRM2.61"></a><a href="snrm2.f.html#SNRM2.1">SNRM2</a> = NORM
RETURN
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment"> End of <a name="SNRM2.64"></a><a href="snrm2.f.html#SNRM2.1">SNRM2</a>.
</span><span class="comment">*</span><span class="comment">
</span> END
</pre>
</body>
</html>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?