Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
21
Task/Nth-root/XPL0/nth-root.xpl0
Normal file
21
Task/Nth-root/XPL0/nth-root.xpl0
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
include c:\cxpl\stdlib;
|
||||
|
||||
func real NRoot(A, N); \Return the Nth root of A
|
||||
real A, N;
|
||||
real X, X0, Y;
|
||||
int I;
|
||||
[X:= 1.0; \initial guess
|
||||
repeat X0:= X;
|
||||
Y:= 1.0;
|
||||
for I:= 1 to fix(N)-1 do Y:= Y*X0;
|
||||
X:= ((N-1.0)*X0 + A/Y) / N;
|
||||
until abs(X-X0) < 1.0E-15; \(until X=X0 doesn't always work)
|
||||
return X;
|
||||
];
|
||||
|
||||
[Format(5, 15);
|
||||
RlOut(0, NRoot( 2., 2.)); CrLf(0);
|
||||
RlOut(0, Power( 2., 0.5)); CrLf(0); \for comparison
|
||||
RlOut(0, NRoot(27., 3.)); CrLf(0);
|
||||
RlOut(0, NRoot(1024.,10.)); CrLf(0);
|
||||
]
|
||||
Loading…
Add table
Add a link
Reference in a new issue