Jump to content

Thiele's interpolation formula: Difference between revisions

Line 698:
 
=={{header|Julia}}==
Accuracy improves with a larger table and smaller step size.
{{trans|C}}
<lang julia>const N = 32256
const N2 = N * div(N - 1, 2)
const step = 0.0501
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 + 1] - x[i + n + 1]) / (rho(x, y, rhocache, i, n - 1) -
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 - 1) * step
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.1415924805444
3.141592653589818
3.6855346281199073
3.141592653589824
3.1415976324027914
</pre>
 
4,105

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.