25 lines
690 B
Plaintext
25 lines
690 B
Plaintext
' Nth root
|
|
DECLARE FUNCTION NthRoot# (N%, X#, Precision#)
|
|
X# = 144
|
|
PRINT "Finding the nth root of"; X#; "to 6 decimal places"
|
|
PRINT " x n root x ^ (1 / n)"
|
|
PRINT "--------------------------------------"
|
|
FOR I% = 1 TO 8
|
|
PRINT USING "### "; X#;
|
|
PRINT USING "#### "; I%;
|
|
PRINT USING "###.######"; NthRoot#(I%, X#, .0000001);
|
|
PRINT USING " ###.######"; X# ^ (1 / I%)
|
|
NEXT I%
|
|
END
|
|
|
|
FUNCTION NthRoot# (N%, X#, Precision#)
|
|
' Returns the Nth root of value X to stated Precision
|
|
X0# = X#
|
|
X1# = X# / N% ' initial guess
|
|
DO WHILE ABS(X1# - X0#) > Precision#
|
|
X0# = X1#
|
|
X1# = ((N% - 1) * X1# + X# / X1# ^ (N% - 1)) / N%
|
|
LOOP
|
|
NthRoot# = X1#
|
|
END FUNCTION
|