Re: Order of parameters in early SIGN(A,B) function?
- From: "James Van Buskirk" <not_valid@xxxxxxxxxxx>
- Date: Sat, 16 May 2009 18:10:47 -0600
"Terence" <tbwright@xxxxxxxxx> wrote in message
news:d93f0a51-fcc5-44ee-bd01-6a0bc143477f@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
I am working on some old (1966) Fortran programs, converted from
Fortran II.
I have just met this use of the SIGN function in a matrix rotation
situation (Jacobi).
The comment says the following lines compute a Tangent, then a Sine
and Cosine.
As I understand the modern use of SIGN(A,B), it transfers the sign of
the B parameter to the A parameter. Yet here, the A parameter is
always of absolute magnitude 2.0 and the related sine and cosine
therefore also fixed.
But Cosine is calculated from the Tangent and the Sine will be +/-
twice the Tangent.
Is it possible that the huge first line computation of "B" computes
only a sign, to be tranferred to a magnitude of 2.0 as the A value?
Or were the SIGN parameters of Fortran II interchanged from the the
current understanding?
(I have completed all the D,M,S and most X series of the 56 BMD
programs; this is an outstanding 6M after which I have only 14 more,
the T(2),R(4) and V(8) series to rewrite).
C COMPUTE TANGENT, SINE AND COSINE,H(I,I),H
(J,J)
150 TANG=SIGN(2.0,(H(IPIV,IPIV)-H(JPIV,JPIV)))*H(IPIV,JPIV)/
1(ABS(H(IPIV,IPIV)-H(JPIV,JPIV))+SQRT((H(IPIV,IPIV)-H(JPIV,JPIV))
**2
+4.0*H(IPIV,JPIV)**2))
COSINE=1.0/SQRT(1.0+TANG**2)
SINE=TANG*COSINE
C
HII=H(IPIV,IPIV)
H(IPIV,IPIV)=
1 COSINE**2*(HII+TANG*(2.0*H(IPIV,JPIV)+TANG*H(JPIV,JPIV)))
H(JPIV,JPIV)=
1 COSINE**2*(H(JPIV,JPIV)-TANG*(2.0*H(IPIV,JPIV)-TANG*HII))
H(IPIV,JPIV)=0.0
I think you're miscounting parentheses.
150 TANG=SIGN(2.0,(H(IPIV,IPIV)-H(JPIV,JPIV)))*H(IPIV,JPIV)/^ ^
The perentheses surrounding the arguments to the SIGN function
are as indicated above. It looks like the whole expression is
intended to solve the quadratic eqaution
A*x**2+B*x+C == 0
with
A = H(IPIV,JPIV)
B = H(IPIV,IPIV)-H(JPIV,JPIV)
C = -H(IPIV,JPIV)
The solution is
x = (-B+-sqrt(B**2-4*A*C))/(2*A) = 2*(-C)/(B+-sqrt(B**2-4*A*C))
The complicated expression picks the smaller root in absolute
value.
--
write(*,*) transfer((/17.392111325966148d0,6.5794487871554595D-85, &
6.0134700243160014d-154/),(/'x'/)); end
.
- Follow-Ups:
- Re: Order of parameters in early SIGN(A,B) function?
- From: Terence
- Re: Order of parameters in early SIGN(A,B) function?
- References:
- Order of parameters in early SIGN(A,B) function?
- From: Terence
- Order of parameters in early SIGN(A,B) function?
- Prev by Date: Order of parameters in early SIGN(A,B) function?
- Next by Date: Re: Order of parameters in early SIGN(A,B) function?
- Previous by thread: Order of parameters in early SIGN(A,B) function?
- Next by thread: Re: Order of parameters in early SIGN(A,B) function?
- Index(es):
Relevant Pages
|