50 likes | 199 Views
Writing Programs. Comment Translation Progressive Envelopment. Bisection Method of Root Finding. Bisection. Algorithm Initialization Begin Loop Single step calculations e.g., X K = F(X K-1 ) Test for early exit End Loop. FORTRAN X = X0 DO K = 1, MAXK XT = X X = F(X)
E N D
Writing Programs • Comment Translation • Progressive Envelopment
Bisection Method of Root Finding Bisection
Algorithm Initialization Begin Loop Single step calculations e.g., XK = F(XK-1) Test for early exit End Loop FORTRAN X = X0 DO K = 1, MAXK XT = X X = F(X) PR = ABS( (XXT) / X ) IF( PR .LT. PRCSN ) GOTO 10 ENDDO 10 CONTINUE Iteration
Comment Translation Initialize XL, XR Set KMAX, PRCSN Test F(XL) & F(XR) for early exit Begin Loop: Set XM Test F(XM) for early exit Choose new XL, XR End loop Exit: Output End Program Programs: HTMLDOC
10 CONTINUE WRITE(*,*) ‘Root at X = ‘, XM WRITE(*,*) ‘ F(X) = ‘, F(XM) END Progressive Envelopment XL = XR = DO K = 1, KMAX XM = ( XL+XR ) / 2. IF( F(XM) .LE. PRCSN ) GOTO 10 IF( F(XM)*F(XR) .LT. 0. ) XL = XM IF( F(XM)*F(XL) .LT. 0. ) XR = XM ENDDO ProgramGraph