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