1 | % 'DXYMatrix': calculate the matrix of thin-plate shell derivatives |
---|
2 | % |
---|
3 | % function DMXY = DXYMatrix(dsites,ctrs) |
---|
4 | % |
---|
5 | % INPUT: |
---|
6 | % dsites: M x s matrix of interpolation site coordinates (s=space dimension) |
---|
7 | % ctrs: N x s matrix of centre coordinates (initial data) |
---|
8 | % |
---|
9 | % OUTPUT: |
---|
10 | % DMXY: Mx(N+1+s)xs matrix corresponding to M interpolation sites and |
---|
11 | % N centres, with s=space dimension, DMXY(:,:,k) gives the derivatives |
---|
12 | % along dimension k (=x, y,z) after multiplication by the N+1+s tps sources. |
---|
13 | function DMXY = tps_eval_dxy(dsites,ctrs) |
---|
14 | %% matrix declarations |
---|
15 | [M,s] = size(dsites); [N,s] = size(ctrs); |
---|
16 | Dsites=zeros(M,N,s); |
---|
17 | DM = zeros(M,N); |
---|
18 | DMXY = zeros(M,N+1+s,s); |
---|
19 | |
---|
20 | %% Accumulate sum of squares of coordinate differences |
---|
21 | % The ndgrid command produces two MxN matrices: |
---|
22 | % Dsites, consisting of N identical columns (each containing |
---|
23 | % the d-th coordinate of the M interpolation sites) |
---|
24 | % Ctrs, consisting of M identical rows (each containing |
---|
25 | % the d-th coordinate of the N centers) |
---|
26 | for d=1:s |
---|
27 | [Dsites(:,:,d),Ctrs] = ndgrid(dsites(:,d),ctrs(:,d));%d coordinates of interpolation points (Dsites) and initial points (Ctrs) |
---|
28 | DM = DM + (Dsites(:,:,d)-Ctrs).^2;% add d component squared |
---|
29 | end |
---|
30 | |
---|
31 | %% calculate mtrix of tps derivatives |
---|
32 | DM(DM~=0) = log(DM)+1; %=2 log(r)+1 derivative of the tps r^2 log(r) |
---|
33 | for d=1:s |
---|
34 | DMXY(:,1:N,d)=Dsites(:,:,d).*DM; |
---|
35 | DMXY(:,N+1+d,d)=1;% effect of mean gradient |
---|
36 | end |
---|