Dear Researchers

I have found two methods to find the distance matrix of Radial Basis function in MATLAB. Can any one tell me which method is correct one because I am getting different values for distance matrix but  rules are same for both matrix that is symmetric matrix. diagonal matrix is zero and both are non singular. 

Your answers will be highly appreciable.

dsites =

X     Y

1     8

4     7

6     8

7     0

1     4

6     0

0     1

4     6

3     7

8     4

distances=dsites*dsites';

>> lsq=diag(distances);

>> distancematrix=sqrt(repmat(lsq,1,10)+repmat(lsq,1,10)'-2*distances)

distancematrix =

0 3.1623 5.0000 10.0000 4.0000 9.4340 7.0711 3.6056 2.2361 8.0623

3.1623 0 2.2361 7.6158 4.2426 7.2801 7.2111 1.0000 1.0000 5.0000

5.0000 2.2361 0 8.0623 6.4031 8.0000 9.2195 2.8284 3.1623 4.4721

10.0000 7.6158 8.0623 0 7.2111 1.0000 7.0711 6.7082 8.0623 4.1231

4.0000 4.2426 6.4031 7.2111 0 6.4031 3.1623 3.6056 3.6056 7.0000

9.4340 7.2801 8.0000 1.0000 6.4031 0 6.0828 6.3246 7.6158 4.4721

7.0711 7.2111 9.2195 7.0711 3.1623 6.0828 0 6.4031 6.7082 8.5440

3.6056 1.0000 2.8284 6.7082 3.6056 6.3246 6.4031 0 1.4142 4.4721

2.2361 1.0000 3.1623 8.0623 3.6056 7.6158 6.7082 1.4142 0 5.8310

8.0623 5.0000 4.4721 4.1231 7.0000 4.4721 8.5440 4.4721 5.8310 0

Other method is

function DM=verDistanceMatrix(dsites,ctrs)

[M,s]=size(dsites);

[N,s]=size(ctrs);

DM=zeros(M,N);

for d =1:s

[dr,cc]=ndgrid(dsites(:,d), ctrs(:,d));

DM=DM+(dr-cc).^2;

DM=sqrt(DM);

VerifyDM =

0 2.0000 2.2361 8.3666 4.0000 8.3066 7.0711 2.6458 1.7321 4.7958

2.0000 0 1.7321 7.2111 3.4641 7.1414 6.3246 1.0000 1.0000 3.6056

2.2361 1.7321 0 8.0623 4.5826 8.0000 7.4162 2.4495 2.0000 4.2426

8.3666 7.2111 8.0623 0 4.6904 1.0000 2.8284 6.2450 7.2801 4.1231

4.0000 3.4641 4.5826 4.6904 0 4.5826 3.1623 2.6458 3.3166 2.6458

8.3066 7.1414 8.0000 1.0000 4.5826 0 2.6458 6.1644 7.2111 4.2426

7.0711 6.3246 7.4162 2.8284 3.1623 2.6458 0 5.3852 6.2450 4.1231

2.6458 1.0000 2.4495 6.2450 2.6458 6.1644 5.3852 0 1.4142 2.8284

1.7321 1.0000 2.0000 7.2801 3.3166 7.2111 6.2450 1.4142 0 3.7417

4.7958 3.6056 4.2426 4.1231 2.6458 4.2426 4.1231 2.8284 3.7417 0

More Zuhaib Nazir's questions See All
Similar questions and discussions