37 lines
342 B
Plaintext
37 lines
342 B
Plaintext
precision 6
|
|
|
|
let a = int(rnd * 5999) + 2
|
|
|
|
print "calculating nth root of ", a, "..."
|
|
|
|
for n = 1 to 10
|
|
|
|
gosub nroot
|
|
print n, " : ", y
|
|
|
|
next n
|
|
|
|
end
|
|
|
|
sub nroot
|
|
|
|
let p = .00001
|
|
|
|
let x = a
|
|
let y = a / n
|
|
|
|
do
|
|
|
|
if abs(x - y) > p then
|
|
|
|
let x = y
|
|
let y = ((n - 1) * y + a / y ^ (n - 1)) / n
|
|
|
|
endif
|
|
|
|
wait
|
|
|
|
loop abs(x - y) > p
|
|
|
|
return
|