Bilinear interpolation: Difference between revisions
Content added Content deleted
m (→{{header|J}}) |
(→{{header|J}}: generalization) |
||
Line 105: | Line 105: | ||
<lang J> |
<lang J> |
||
Note 'FEA' |
Note 'FEA' |
||
Here we develop a general method to generate isoparametric interpolants. |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
at the coordinates within the element with the known values at the nodes. |
|||
⚫ | |||
⚫ | |||
Line 115: | Line 118: | ||
| | |
| | |
||
| (0,0) | |
| (0,0) | |
||
| * | |
| * | |
||
| | |
| | |
||
| | |
| | |
||
| | |
| | |
||
+---------------+ |
+---------------+ |
||
Line 126: | Line 129: | ||
f1( 1,-1) = 1, f1(all other corners) is 0. |
f1( 1,-1) = 1, f1(all other corners) is 0. |
||
... |
... |
||
The coordinates (xi,eta) are a vector length 2 as argument y |
|||
Supply to interpolate the function values at nodes 0 1 2 and 3 as the x argument. |
|||
⚫ | |||
Choose a shape function. |
|||
f0 =: 1r4 * [: */ 1 1&- NB. f0(xi,eta) = (1-xi)(1-eta)/4 |
|||
Use shape functions C0 + C1*xi + C2*eta + C3*xi*eta . |
|||
Given (xi,eta) as the vector y form a vector of the |
|||
f2 =: _1r4 * [: */ 1 _1&- NB. ... |
|||
coefficients of the constants (1, xi, eta, and their product) |
|||
f3 =: 1r4 * [: */ _1 _1&- |
|||
shape_function =: 1 , {. , {: , */ |
|||
functions =: f0`f1`f2`f3`:0 |
|||
CORNERS NB. are the ordered coordinates of the corners |
|||
⚫ | |||
_1 _1 |
|||
NB. prove the function values at the corners are correct. |
|||
1 _1 |
|||
assert (=i.4) -: functions"1 CORNERS NB. 4 by 4 identity matrix |
|||
_1 1 |
|||
1 1 |
|||
(=i.4) NB. rows of the identity matrix are the values of each shape functions at each corner |
|||
1 0 0 0 |
|||
0 1 0 0 |
|||
0 0 1 0 |
|||
0 0 0 1 |
|||
(=i.4x) %. shape_function"1 x: CORNERS NB. Compute the values of the constants as rational numbers. |
|||
1r4 1r4 1r4 1r4 |
|||
_1r4 1r4 _1r4 1r4 |
|||
_1r4 _1r4 1r4 1r4 |
|||
1r4 _1r4 _1r4 1r4 |
|||
This method extends to higher order interpolants having more nodes or to other dimensions. |
|||
⚫ | |||
⚫ | |||
mp =: +/ .* NB. matrix product |
|||
⚫ | |||
shape_function =: 1 , {. , {: , */ |
|||
COEFFICIENTS =: (=i.4) %. shape_function"1 CORNERS |
|||
shape_functions =: COEFFICIENTS mp shape_function |
|||
⚫ | |||
</lang> |
</lang> |
||
<pre> |
<pre> |
||
Note |
Note 'demonstrate the interpolant with a saddle' |
||
lower left has value 1, |
lower left has value 1, |
||
lower right: 2 |
lower right: 2 |
||
upper left: 2.2 |
upper left: 2.2 |
||
upper right: 0.7 |
upper right: 0.7 |
||
GRID is an array of coordinate pairs (hence rank 3) |
|||
ordered so that _1 _1 is in the lower left of the picture, |
|||
directed with 1 _1 to lower right. |
|||
) |
) |
||
Line 158: | Line 178: | ||
viewmat SADDLE |
viewmat SADDLE |
||
</pre> |
</pre> |
||
[[Image:J_bilinear_interpolant.jpg |
[[Image:J_bilinear_interpolant.jpg]] |
||
=={{header|Racket}}== |
=={{header|Racket}}== |