公理,174字节
f(n:PI):Complex Float==(n>10^4=>%i;m:=digits(n+10);e:=10^(-n-7);a:=0;repeat(b:=a+(cos(a)-a)/(sin(a)+1.);if a~=0 and a-b<e then break;a:=b);a:=floor(b*10^n)/10.^n;digits(m);a)
取消评论
-- Input: n:PI numero di cifre
-- Output la soluzione x a cos(x)=x con n cifre significative dopo la virgola
-- Usa il metodo di Newton a_0:=a a_(n+1)=a_n-f(a_n)/f'(a_n)
fo(n:PI):Complex Float==
n>10^4=>%i
m:=digits(n+10)
e:=10^(-n-7)
a:=0 -- Punto iniziale
repeat
b:=a+(cos(a)-a)/(sin(a)+1.)
if a~=0 and a-b<e then break
a:=b
a:=floor(b*10^n)/10.^n
digits(m)
a
结果:
(3) -> for i in 1..10 repeat output[i,f(i)]
[1.0,0.7]
[2.0,0.73]
[3.0,0.739]
[4.0,0.739]
[5.0,0.73908]
[6.0,0.739085]
[7.0,0.7390851]
[8.0,0.73908513]
[9.0,0.739085133]
[10.0,0.7390851332]
Type: Void
Time: 0.12 (IN) + 0.10 (EV) + 0.12 (OT) + 0.02 (GC) = 0.35 sec
(4) -> f 300
(4)
0.7390851332 1516064165 5312087673 8734040134 1175890075 7464965680 635773284
6 5488354759 4599376106 9317665318 4980124664 3987163027 7149036913 084203157
8 0440574620 7786885249 0389153928 9438845095 2348013356 3127677223 158095635
3 7765724512 0437341993 6433512538 4097800343 4064670047 9402143478 080271801
8 8377113613 8204206631
Type: Complex Float
Time: 0.03 (IN) + 0.07 (OT) = 0.10 sec
我将使用牛顿法,因为它比“重复cos(x)法”更快
800 92x
1000 153x
2000 379x
在第一列中有位数,在第二列中有牛顿法比使用重复cos(x)法要快多少。早上好
Decimal
?