Next: Nested DO Loops
Up: Nested DO Loops
Previous: Nested DO Loops

Approximation

In mathematics, repetition is commonly used when computing approximations. For example, consider the problem of computing the square root of a real number. It has been known since the first century A.D. that if guess is an approximation to the square root of x, then we can get a better approximation by averaging guess and x/guess.

Take a look at ``sroot1.f'' from your ``examples'' directory (or view it directly). The interesting part of the code is the implementation of the ``SROOT'' function. The main program uses ``SROOT'' to compute the square root of a real number and prints out that result, along with the value computed by the intrinsic function ``SQRT''. That way, you can compare how the two functions perform. Run the program a few times to get a feel for how it works.

Here are a couple of questions to think about

  1. Why do we initialize ``GUESS'' to 1 before the loop?

    Click here for the answer

  2. What would be a better initial value for ``GUESS''?

    Click here for the answer

  3. What is the purpose of the ``COUNT'' argument to ``SROOT''?

    Click here for the answer

  4. Isn't it kind of strange to have two arguments to a square root function? Isn't there a better way of deciding how many successive approximations to compute?

    Click here for the answer


Next: Nested DO Loops
Up: Nested DO Loops
Previous: Nested DO Loops

Hamlet Project
hamlet@cs.utah.edu