Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
15
Task/Nth-root/S-BASIC/nth-root-1.basic
Normal file
15
Task/Nth-root/S-BASIC/nth-root-1.basic
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
rem - return nth root of x
|
||||
function nthroot(x, n = real) = real
|
||||
end = exp((1.0 / n) * log(x))
|
||||
|
||||
rem - exercise the routine by finding successive roots of 144
|
||||
var i = integer
|
||||
|
||||
print "Finding the nth root of x"
|
||||
print " x n root"
|
||||
print "-----------------------"
|
||||
for i = 1 to 8
|
||||
print using "### #### ###.####"; 144; i; nthroot(144, i)
|
||||
next i
|
||||
|
||||
end
|
||||
23
Task/Nth-root/S-BASIC/nth-root-2.basic
Normal file
23
Task/Nth-root/S-BASIC/nth-root-2.basic
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
rem - return the nth root of real.double value x to stated precision
|
||||
function nthroot(n, x, precision = real.double) = real.double
|
||||
var x0, x1 = real.double
|
||||
x0 = x
|
||||
x1 = x / n rem - initial guess
|
||||
while abs(x1 - x0) > precision do
|
||||
begin
|
||||
x0 = x1
|
||||
x1 = ((n-1.0) * x1 + x / x1 ^ (n-1.0)) / n
|
||||
end
|
||||
end = x1
|
||||
|
||||
rem -- exercise the routine
|
||||
|
||||
var i = integer
|
||||
print "Finding the nth root of 144 to 6 decimal places"
|
||||
print " x n root"
|
||||
print "------------------------"
|
||||
for i = 1 to 8
|
||||
print using "### #### ###.######"; 144; i; nthroot(i, 144.0, 1E-7)
|
||||
next i
|
||||
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue