source: trunk/src/tps_eval.m @ 511

Last change on this file since 511 was 434, checked in by sommeria, 12 years ago

corrections in the use of get_field
test_tps introduced, to test thin plate shell functions
tps-eval_dxy corrected (bug on the calculation of the derivatives fixed)

File size: 1.5 KB
[356]1%'tps_eval': calculate the thin plate spline (tps) interpolation at a set of points
[434]2% see tps_coeff.m for more information and test_tps.m for an example
4% function EM = tps_eval(dsites,ctrs)
7% EM:  Mx(N+s) matrix representing the contributions at the M sites
8%   from unit sources located at each of the N centers, + (s+1) columns
9%   representing the contribution of the linear gradient part.
[434]10%  use : U_interp=EM*U_tps
[434]13%dsites:  Mxs matrix representing the postions of the M 'observation' sites, with s the space dimension
14%ctrs: Nxs matrix  representing the postions of the N centers, sources of the tps,
16% related functions:
17% tps_coeff, tps_eval_dxy
[356]19function EM = tps_eval(dsites,ctrs)
20[M,s] = size(dsites); [N,s] = size(ctrs);
21EM = zeros(M,N);
23% calculate distance matrix: accumulate sum of squares of coordinate differences
24% The ndgrid command produces two MxN matrices:
25%   Dsite, consisting of N identical columns (each containing
26%       the d-th coordinate of the M data sites)
27%   Ctrs, consisting of M identical rows (each containing
28%       the d-th coordinate of the N centers)
29for d=1:s
30 [Dsites,Ctrs] = ndgrid(dsites(:,d),ctrs(:,d));
31 EM = EM + (Dsites-Ctrs).^2;%EM=square of distance matrices
34% calculate tps
36EM(np) = EM(np).*log(EM(np))/2;%= tps formula r^2 log(r) (EM=r^2)
38% add linear gradient part:
39EM = [EM ones(M,1) dsites];
Note: See TracBrowser for help on using the repository browser.