Interpolation¶
CalcpadCE ships three built-in interpolators — take() for nearest-value lookup, line() for piecewise linear interpolation, and spline() for smooth Hermite cubic-spline curves — exposed as plain functions usable anywhere in a worksheet.
The interpolation primer lays the three methods side-by-side on a single dataset, then re-uses them in a practical engineering case: deriving wind-load height factors \(k_z\) for two terrain categories from tabulated code values. The function-approximation study measures how well each scheme reproduces analytical exponential and trigonometric functions sampled on a coarse grid, giving a quick visual feel for accuracy and overshoot. The bilinear-style table lookup chains 1D splines along both axes to interpolate a tabulated \(T(i,\, j)\) surface — the canonical pattern for working with two-input design tables.
Sample positions, values and interpolation method are parametric, so each worksheet doubles as a sandbox for choosing the right method on real engineering data.
Interpolation of Functions¶
Reconstructs an exponential and a trigonometric function from coarse samples using nearest-value, linear and Hermite-spline interpolation. A side-by-side accuracy comparison that quickly reveals overshoot, kinks and where the smooth spline pays off.
'<h4>Exponential function</h4>
f(x) = e^x
'Values
f_1 = f(0)
f_2 = f(1)
f_3 = f(2)
f_4 = f(3)
f_5 = f(4)
f_6 = f(5)
f_7 = f(6)
n(x) = x + 1' - variable transformation
'Discrete -'f_c(x) = take(n(x); f_1; f_2; f_3; f_4; f_5; f_6; f_7)
'Linear -'f_l(x) = line(n(x); f_1; f_2; f_3; f_4; f_5; f_6; f_7)
'Spline -'f_s(x) = spline(n(x); f_1; f_2; f_3; f_4; f_5; f_6; f_7)
'Plot'
$Plot{f(x) & f_c(x) & f_l(x) & f_s(x) @ x = 0 : 5}
'<h4>Trigonometric function</h4>
#deg
f(x) = sin(x)
'Values
f_1 = f(0)
f_2 = f(30)
f_3 = f(60)
f_4 = f(90)
f_5 = f(120)
f_6 = f(150)
f_7 = f(180)
n(x) = x/30 + 1' - variable transformation
'Discrete -'f_c(x) = take(n(x); f_1; f_2; f_3; f_4; f_5; f_6; f_7)
'Linear -'f_l(x) = line(n(x); f_1; f_2; f_3; f_4; f_5; f_6; f_7)
'Spline -'f_s(x) = spline(n(x); f_1; f_2; f_3; f_4; f_5; f_6; f_7)
'Plot'
$Plot{f(x) & f_c(x) & f_l(x) & f_s(x) @ x = 0 : 180}
f_s(180)
f ( x ) = ex
Values
f1 = f ( 0 ) = 1
f2 = f ( 1 ) = 2.72
f3 = f ( 2 ) = 7.39
f4 = f ( 3 ) = 20.09
f5 = f ( 4 ) = 54.6
f6 = f ( 5 ) = 148.41
f7 = f ( 6 ) = 403.43
n ( x ) = x + 1 - variable transformation
Discrete - fc ( x ) = take ( n ( x ) ; f1; f2; f3; f4; f5; f6; f7 )
Linear - fl ( x ) = line ( n ( x ) ; f1; f2; f3; f4; f5; f6; f7 )
Spline - fs ( x ) = spline ( n ( x ) ; f1; f2; f3; f4; f5; f6; f7 )
Plot
f ( x ) = sin ( x ) !!!
Values
f1 = f ( 0 ) = 0
f2 = f ( 30 ) = 0.5
f3 = f ( 60 ) = 0.866
f4 = f ( 90 ) = 1
f5 = f ( 120 ) = 0.866
f6 = f ( 150 ) = 0.5
f7 = f ( 180 ) = 1.22×10-16
n ( x ) = x30 + 1 !!! - variable transformation
Discrete - fc ( x ) = take ( n ( x ) ; f1; f2; f3; f4; f5; f6; f7 ) !!!
Linear - fl ( x ) = line ( n ( x ) ; f1; f2; f3; f4; f5; f6; f7 ) !!!
Spline - fs ( x ) = spline ( n ( x ) ; f1; f2; f3; f4; f5; f6; f7 )
Plot
fs ( 180 ) = 1.22×10-16
Interpolation¶
Compares take(), line() and spline() on a single dataset, then derives wind-load height factors \(k_z\) for two terrain categories by interpolating tabulated code values.
A compact reference for picking the right scheme when working with discrete engineering tables.
'<h4>Data functions in CalcpadCE</h4>
f_1(x) = take(x; 9; 2; -1; 1; 4.5; 6; -4)' - discrete values (vector) <span style="color:CornflowerBlue;">━━━</span>
f_2(x) = line(x; 9; 2; -1; 1; 4.5; 6; -4)' - linear interpolation <span style="color:YellowGreen;">━━━</span>
f_3(x) = spline(x; 9; 2; -1; 1; 4.5; 6; -4)' - Hermite spline interpolation <span style="color:Tomato;">━━━</span>
'<!--'PlotHeight = 250','PlotWidth = 400'-->
$Plot{f_3(x) & f_2(x) & f_1(x) @ x = 1 : 7}
'<h4>Application - wind load height factors</h4>
'Height above terrain
Z(x) = spline(x; -0.01; 5; 10; 20; 40; 60; 80; 100; 150; 200; 250; 300; 350)
'Load for terrain type A
k_zA(x) = line(x; 0.75; 0.75; 1; 1.25; 1.5; 1.7; 1.85; 2; 2.25; 2.45; 2.65; 2.75; 2.75)
'Load for terrain type B
k_zB(x) = line(x; 0.5; 0.5; 0.65; 0.85; 1.1; 1.3; 1.45; 1.6; 1.9; 2.1; 2.3; 2.5; 2.75)
'Interpolation factor
k(z) = $Root{Z(x) = z @ x = 1 : 12}
'<!--'PlotHeight = 250','PlotWidth = 150'-->
'Chart
$Plot{k_zA(k(z))|z & k_zB(k(z))|z @ z = 0 : 50}
f1 ( x ) = take ( x; 9; 2; -1; 1; 4.5; 6; -4 ) - discrete values (vector) ━━━
f2 ( x ) = line ( x; 9; 2; -1; 1; 4.5; 6; -4 ) - linear interpolation ━━━
f3 ( x ) = spline ( x; 9; 2; -1; 1; 4.5; 6; -4 ) - Hermite spline interpolation ━━━
Height above terrain
Z ( x ) = spline ( x; -0.01; 5; 10; 20; 40; 60; 80; 100; 150; 200; 250; 300; 350 )
Load for terrain type A
kzA ( x ) = line ( x; 0.75; 0.75; 1; 1.25; 1.5; 1.7; 1.85; 2; 2.25; 2.45; 2.65; 2.75; 2.75 )
Load for terrain type B
kzB ( x ) = line ( x; 0.5; 0.5; 0.65; 0.85; 1.1; 1.3; 1.45; 1.6; 1.9; 2.1; 2.3; 2.5; 2.75 )
Interpolation factor
k ( z ) = $Root{Z ( x ) = z; x ∈ [1; 12]}
Chart
Double Interpolation¶
Bilinear-style table lookup that chains 1D Hermite splines along both axes to interpolate a tabulated \(T(i,\, j)\) surface. The canonical pattern for evaluating two-input design tables on intermediate values.
'Input parameters
x(j) = spline(j; 2; 4; 8)'- x values
y(i) = spline(i; 3; 9; 27)'- y values
'Output values
R_1(j) = spline(j; 11; 12; 13)' - first row
R_2(j) = spline(j; 21; 22; 23)' - second row
R_3(j) = spline(j; 31; 32; 39)' - third row
T(i; j) = spline(i; R_1(j); R_2(j); R_3(j))' - complete table
'Calculation of interpolation factors
k_x(x) = $Root{x(j) = x @ j = 1 : 3}
k_y(y) = $Root{y(i) = y @ i = 1 : 3}
'The interpolated function
f(x; y) = T(k_x(x); k_y(y))
'Usage
f(2; 3)
f(5; 5)
f(4; 9)
f(8; 27)
'Table
#val
'<!--'i = 0''j = 0'-->
'<table class="bordered">
'<tr><th></th>
#repeat 3
'<th><!--'j = j + 1'-->'x(j)'</th>
#loop
'</tr>
#repeat 3
'<tr><th><!--'i = i + 1''j = 0'-->'y(i)'</th>
#repeat 3
'<td><!--'j = j + 1'-->'T(i; j)'</td>
#loop
'</tr>
#loop
'</table>
#equ
PlotHeight = 300
PlotWidth = PlotHeight
'Plot
$Map{f(x; y) @ x = 2 : 8 & y = 3 : 27}
Input parameters
x ( j ) = spline ( j; 2; 4; 8 ) - x values
y ( i ) = spline ( i; 3; 9; 27 ) - y values
Output values
R1 ( j ) = spline ( j; 11; 12; 13 ) - first row
R2 ( j ) = spline ( j; 21; 22; 23 ) - second row
R3 ( j ) = spline ( j; 31; 32; 39 ) - third row
T ( i; j ) = spline ( i; R1 ( j ) ; R2 ( j ) ; R3 ( j ) ) - complete table
Calculation of interpolation factors
kx ( x ) = $Root{x ( j ) = x; j ∈ [1; 3]}
ky ( y ) = $Root{y ( i ) = y; i ∈ [1; 3]}
The interpolated function
f ( x; y ) = T ( kx ( x ) ; ky ( y ) )
Usage
f ( 2; 3 ) = 11
f ( 5; 5 ) = 24.35
f ( 4; 9 ) = 22
f ( 8; 27 ) = 39
Table
| 2 | 4 | 8 | |
|---|---|---|---|
| 3 | 11 | 12 | 13 |
| 9 | 21 | 22 | 23 |
| 27 | 31 | 32 | 39 |
PlotHeight = 300
PlotWidth = PlotHeight = 300
Plot
Spotted an error? Edit these examples.