Jump to content

Thiele's interpolation formula: Difference between revisions

Added 11l
(Add Rust implementation)
(Added 11l)
Line 26:
#* &nbsp; <big><big> 4 &times; tan<sup>-1</sup> 1 = <math>\pi</math></big></big>
<br><br>
 
=={{header|11l}}==
{{trans|Python}}
 
<lang 11l>F thieleInterpolator(x, y, val)
V ρ = enumerate(y).map((i, yi) -> [yi] * (@y.len - i))
L(i) 0 .< ρ.len - 1
ρ[i][1] = (x[i] - x[i + 1]) / (ρ[i][0] - ρ[i + 1][0])
L(i) 2 .< ρ.len
L(j) 0 .< ρ.len - i
ρ[j][i] = (x[j] - x[j + i]) / (ρ[j][i - 1] - ρ[j + 1][i - 1]) + ρ[j + 1][i - 2]
V ρ0 = ρ[0]
F t(xin)
V a = 0.0
L(i) (@ρ0.len - 1 .< 1).step(-1)
a = (xin - @x[i - 1]) / (@ρ0[i] - @ρ0[i - 2] + a)
R @y[0] + (xin - @x[0]) / (@ρ0[1] + a)
R t(val)
 
V xVal = (0.<32).map(i -> i * 0.05)
V tSin = xVal.map(x -> sin(x))
V tCos = xVal.map(x -> cos(x))
V tTan = xVal.map(x -> tan(x))
V iSin = thieleInterpolator(tSin, xVal, 0.5)
V iCos = thieleInterpolator(tCos, xVal, 0.5)
V iTan = thieleInterpolator(tTan, xVal, 1)
print(‘#.14’.format(6 * iSin))
print(‘#.14’.format(3 * iCos))
print(‘#.14’.format(4 * iTan))</lang>
 
{{out}}
<pre>
3.14159265358979
3.14159265358979
3.14159265358980
</pre>
 
=={{header|Ada}}==
1,481

edits

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