0001 function [grad, Itbl, Dim] = vb_spherical_grad_F(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 [F, Itbl, dim, Rmax] = vb_spherical_harmo_F(X,N,Rmax);
0024
0025 NP = size(F,1);
0026 D = (N+1)^2;
0027
0028 W1 = zeros(NP,1);
0029 W2 = zeros(NP,1);
0030
0031 grad = zeros(NP,D);
0032
0033 for n = 0:N
0034 for m = 0:n
0035
0036 n_idx = n + 1;
0037 m_idx = m + 1;
0038
0039 if n_idx < 1 | n_idx > size(Itbl,1) | m_idx < 1 | m_idx > size(Itbl,2)
0040 continue;
0041 end
0042
0043
0044 column_num = Itbl(n_idx,m_idx,1);
0045 if column_num < 1, continue; end;
0046
0047
0048 [W1, valid1] = vb_spherical_harmo_W(n,m,F,Itbl,'+',0);
0049 [W2, valid2] = vb_spherical_harmo_W(n,m,F,Itbl,'-',0);
0050 x = 0.5 * (W1 + W2);
0051
0052
0053 [W1, valid1] = vb_spherical_harmo_W(n,m,F,Itbl,'+',1);
0054 [W2, valid2] = vb_spherical_harmo_W(n,m,F,Itbl,'-',1);
0055 y = 0.5 * (W1 - W2);
0056
0057
0058 [W1, valid] = vb_spherical_harmo_W(n,m,F,Itbl,'0',0);
0059 z = W1;
0060
0061 grad(:,column_num) = x .* Q(:,1) + y .* Q(:,2) + z .* Q(:,3);
0062
0063
0064 column_num = Itbl(n_idx,m_idx,2);
0065 if column_num < 1, continue; end;
0066
0067
0068 [W1, valid1] = vb_spherical_harmo_W(n,m,F,Itbl,'+',1);
0069 [W2, valid2] = vb_spherical_harmo_W(n,m,F,Itbl,'-',1);
0070 x = 0.5 * (W1 + W2);
0071
0072
0073 [W1, valid1] = vb_spherical_harmo_W(n,m,F,Itbl,'+',0);
0074 [W2, valid2] = vb_spherical_harmo_W(n,m,F,Itbl,'-',0);
0075 y = 0.5 * (W2 - W1);
0076
0077
0078 [W1, valid] = vb_spherical_harmo_W(n,m,F,Itbl,'0',1);
0079 z = W1;
0080
0081 grad(:,column_num) = x .* Q(:,1) + y .* Q(:,2) + z .* Q(:,3);
0082
0083 end
0084 end
0085
0086 grad = grad(:,2:D);
0087 Itbl = Itbl - 1;
0088 Dim = dim(:,2:D);
0089 return;