Data update

This commit is contained in:
Ingy döt Net 2025-02-27 18:35:13 -05:00
parent 8e4e15fa56
commit 72eb4943cb
1853 changed files with 35514 additions and 9441 deletions

View file

@ -0,0 +1,47 @@
MODULE NthRoot;
FROM LongMath IMPORT
power;
FROM STextIO IMPORT
WriteString, WriteLn;
FROM SLongIO IMPORT
WriteFixed;
FROM SWholeIO IMPORT
WriteInt;
VAR
X: LONGREAL;
I: CARDINAL;
PROCEDURE Root(X: LONGREAL; N: CARDINAL; Precision: LONGREAL): LONGREAL;
(* Returns the Nth root of value X to stated Precision *)
VAR
X0, X1, NR: LONGREAL;
BEGIN
NR := FLOAT(N);
X0 := X;
X1 := X / NR; (* initial guess *)
WHILE ABS(X1 - X0) > Precision DO
X0 := X1;
X1 := ((NR - 1.0) * X1 + X / power(X1, NR - 1.0)) / NR
END;
RETURN X1
END Root;
BEGIN
X := 144.0;
WriteString("Finding the nth root of ");
WriteFixed(X, 1, 5);
WriteString(" to 6 decimal places");
WriteLn;
WriteString(" x n root x ^ (1 / n)");
WriteLn;
WriteString("----------------------------------------");
WriteLn;
FOR I := 1 TO 8 DO
WriteFixed(X, 1, 5);
WriteInt(I, 7);
WriteFixed(Root(X, I, 1.0E-07), 6, 14);
WriteFixed(power(X, 1. / FLOAT(I)), 6, 14);
WriteLn
END
END NthRoot.