Jump to content

Thiele's interpolation formula: Difference between revisions

m (→‎{{header|Phix}}: added syntax colouring the hard way)
Line 30:
{{trans|Python}}
 
<lang 11l>F thieleInterpolator(x, y, val)
V ρ = enumerate(y).map((i, yi) -> [yi] * (@y.len - i))
L(i) 0 .< ρ.len - 1
Line 40:
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)
Line 49:
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(0.5)))
print(‘#.14’.format(3 * iCos(0.5)))
print(‘#.14’.format(4 * iTan(1)))</lang>
 
{{out}}
1,481

edits

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