Thiele's interpolation formula: Difference between revisions
→{{header|Julia}}
Line 698:
=={{header|Julia}}==
Accuracy improves with a larger table and smaller step size.
{{trans|C}}
<lang julia>const N =
const N2 = N * div(N - 1, 2)
const step = 0.
const xval_table = zeros(Float64, N)
const tsin_table = zeros(Float64, N)
Line 718 ⟶ 719:
idx = (N - 1 - n) * div(N - n, 2) + i
if !haskey(rhocache, idx)
rhocache[idx] = (x[i
rho(x, y, rhocache, i + 1, n - 1)) + rho(x, y, rhocache, i + 1, n - 2)
end
Line 733 ⟶ 734:
function thiele_tables()
for i in 1:N
xval_table[i] = (i
tsin_table[i] = sin(xval_table[i])
tcos_table[i] = cos(xval_table[i])
Line 745 ⟶ 746:
thiele_tables()
</lang>{{output}}<pre>
3.1415926535898335
3.141592653589818
3.141592653589824
</pre>
|