Bilinear interpolation: Difference between revisions

→‎{{header|J}}: generalization
(→‎{{header|J}}: generalization)
Line 105:
<lang J>
Note 'FEA'
Here we develop a general method to generate isoparametric interpolants.
The interpolant is the dot product of the four function values with the values at the nodes.
 
Sum of four linear functions of two variables (xi, eta) is one at each of 4 nodes.
The interpolant is the dot product of the four shape function values with the values at the nodes.evaluated
Let the base element have nodal coordinates (corners) (x,y) with at +/-1.
at the coordinates within the element with the known values at the nodes.
SumThe sum of four linearshape functions of two variables (xi, eta) is one1 at each of 4four nodes.
Let the base element have nodal coordinates (corners)xi, (x,yeta) with atof +/-1.
 
 
Line 115 ⟶ 118:
| |
| (0,0) |
| * | (The usual finite element node order
| | is counter clockwise. My order to
| | me is more reasonable.)
| |
+---------------+
Line 126 ⟶ 129:
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
f1 =: _1r4 *Use [:shape */functions _1C0 + 1&-C1*xi + NB. f1(xi,C2*eta) = (1+ C3*xi)(1-*eta)/4 .
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
CORNERS =: 21 A. -.+:#:i.4
_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.
interpolate =: (+/ .*) functions
 
mp =: +/ .* NB. matrix product
 
CORNERS =: 21 A. -.+:#:i.4
shape_function =: 1 , {. , {: , */
COEFFICIENTS =: (=i.4) %. shape_function"1 CORNERS
shape_functions =: COEFFICIENTS mp shape_function
interpolate =: (+/mp .*) functionsshape_functions
</lang>
<pre>
Note. 'demonstrate the interpolant with a saddle'
lower left has value 1,
lower right: 2
upper left: 2.2
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 ⟶ 178:
viewmat SADDLE
</pre>
 
[[Image:J_bilinear_interpolant.jpg|right]]
 
=={{header|Racket}}==
Anonymous user