Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
30
Task/Nth-root/Picat/nth-root.picat
Normal file
30
Task/Nth-root/Picat/nth-root.picat
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
go =>
|
||||
L = [[2,2],
|
||||
[34,5],
|
||||
[34**5,5],
|
||||
[7131.5**10],
|
||||
[7,0.5],
|
||||
[1024,10],
|
||||
[5642, 125]
|
||||
],
|
||||
foreach([A,N] in L)
|
||||
R = nthroot(A,N),
|
||||
printf("nthroot(%8w,%8w) %20w (check: %w)\n",A,N,R,A**(1/N))
|
||||
end,
|
||||
nl.
|
||||
|
||||
%
|
||||
% x^n = a
|
||||
%
|
||||
% Given a and n, find x (to Precision)
|
||||
%
|
||||
nthroot(A,N) = nthroot(A,N,0.000001).
|
||||
|
||||
nthroot(A,N,Precision) = X1 =>
|
||||
NF = N * 1.0, % float version of N
|
||||
X0 = A / NF,
|
||||
X1 = 1.0,
|
||||
do
|
||||
X0 := X1,
|
||||
X1 := (1.0 / NF)*((NF - 1.0)*X0 + (A / (X0 ** (NF - 1))))
|
||||
while( abs(X0-X1) > Precision).
|
||||
Loading…
Add table
Add a link
Reference in a new issue