Fortran
Project
Iy'th
Roots
1
Introduction
and
Due
Date
An algorithm for finding
a square root
of a given real number,
N, to a given
level,
limit,
of accuracy
is well known'
It
is called the Newton-Riphson
algorithm.
with
;
httle math,
it
can easily
be
modified to
find the nth root of
a number, too.
The compilers on
taz
are
f95 and
gfortran
_
use either one.
tr'or help with
Fortran, refer to
any Fortran
text or look
on the web. There is also a
brief
,,manual,,
in my directory
/hone/UnlClasses/Cscl/Fo
rtran/
on taz.
This assignment
is due on:
Monday,
vrarctr;filt
the start of ciass. There is no
need for a formal
report.
2
The
Algorithm
we begin by
"guessing" the answer;
let o-ur guess
be G.
G islikely
to be incorrec
t;
Iet G
:
t/N +
6.
Therefore, doing the division
,
N-LG
:
vN
_*d
+
. .,
i.e.
wk
=
JN
_a.
li *"
_rerpo.late
between
G(orfN*d)
and
lvp(or\/N-
d),weget,roughly,\/Iv,-1;'"";""r","'*"ethatiscloser
to the true value of
t/N than
was G, which becomes
our next
,,guess,,,
l/G
If
we continue
in this
way' we can get
arbitrarily
close to the
correct value; i.e.,
to within
limit of the correct value. An
acceptable
value for the
initial
guess
is
L.0.
CSC
fll
What to
Do
Spring 2010
(A) code
the square root algorithm
with limit
set
to 0.0005.
Modify the algorithm
so that the
output includes the
number of guesses
that were
made. Run
it
on u*u"tiy the numbers
0.5,
1.0, 100.0, 1b0.00, 5000.0 and 62632.82.
(B) Examine
the math behind the
square root
algorithm
and use
it
to
develop an
analogous
algorithm (including
the outputting
of the nuniber of
guesses
made) to find
'tlF
(';;"g"o,";
N real).
(Hint: interpoiate
between the guess,
c, uri
wyc,,-r.In
computing
G,-1,
use a
loop, not the
ex-p
functjon.)
use that algorithm,
with
limit:0.0005,
to hnd exactly
Vnn,
{n;sr,
in4'.o,
arrd
ylnt23.
What
to
Ttrrn
In
1. A iisting of
the source code and the run
in
(A).
2. The math (pen
and paper is okay) used
to develop the
itself.
3. A listing
of the source
code and the
run
in (B).
algorithm
in (B) and
the algorithm