0001 function [grad, Itbl, Dim] = vb_spherical_grad_G(X, Q, N, Rmax)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024 [G, Itbl, dim, Rmax] = vb_spherical_harmo_G(X,N+1,Rmax);
0025
0026 NP = size(G,1);
0027 D = (N+1)^2;
0028
0029 V1 = zeros(NP,1);
0030 V2 = zeros(NP,1);
0031
0032 grad = zeros(NP,D);
0033
0034 for n = 0:N
0035 for m = 0:n
0036
0037 n_idx = n + 1;
0038 m_idx = m + 1;
0039
0040 if n_idx < 1 | n_idx > size(Itbl,1) | m_idx < 1 | m_idx > size(Itbl,2)
0041 continue;
0042 end
0043
0044
0045 column_num = Itbl(n_idx,m_idx,1);
0046 if column_num < 1, continue; end;
0047
0048
0049 [V1, valid1] = vb_spherical_harmo_V(n,m,G,Itbl,'+',0);
0050 [V2, valid2] = vb_spherical_harmo_V(n,m,G,Itbl,'-',0);
0051 x = 0.5 * (V1 + V2);
0052
0053
0054 [V1, valid1] = vb_spherical_harmo_V(n,m,G,Itbl,'+',1);
0055 [V2, valid2] = vb_spherical_harmo_V(n,m,G,Itbl,'-',1);
0056 y = 0.5 * (V1 - V2);
0057
0058
0059 [V1, valid] = vb_spherical_harmo_V(n,m,G,Itbl,'0',0);
0060 z = V1;
0061
0062 grad(:,column_num) = x .* Q(:,1) + y .* Q(:,2) + z .* Q(:,3);
0063
0064
0065 column_num = Itbl(n_idx,m_idx,2);
0066 if column_num < 1, continue; end;
0067
0068
0069 [V1, valid1] = vb_spherical_harmo_V(n,m,G,Itbl,'+',1);
0070 [V2, valid2] = vb_spherical_harmo_V(n,m,G,Itbl,'-',1);
0071 x = 0.5 * (V1 + V2);
0072
0073
0074 [V1, valid1] = vb_spherical_harmo_V(n,m,G,Itbl,'+',0);
0075 [V2, valid2] = vb_spherical_harmo_V(n,m,G,Itbl,'-',0);
0076 y = 0.5 * (V2 - V1);
0077
0078
0079 [V1, valid] = vb_spherical_harmo_V(n,m,G,Itbl,'0',1);
0080 z = V1;
0081
0082 grad(:,column_num) = x .* Q(:,1) + y .* Q(:,2) + z .* Q(:,3);
0083
0084 end
0085 end
0086
0087
0088
0089
0090 Itbl = Itbl(1:N+1,1:N+1,:);
0091 Dim = dim(:,1:D);
0092 return;