Problems when sort 'sym' variables and 'vpa' double-precision number.
Show older comments
% this is my data
X = [-7.82 -4.58 -3.97
-6.68 3.16 2.71
4.36 -2.19 2.09
6.72 0.88 2.80
-8.64 3.06 3.50
-6.87 0.57 -5.45
4.47 -2.62 5.76
6.73 -2.01 4.18
-7.71 2.34 -6.33
-6.91 -0.49 -5.68
6.18 2.81 5.82
6.72 -0.93 -4.04
-6.25 -0.26 0.56
-6.94 -1.22 1.13
8.09 0.20 2.25
6.81 0.17 -4.15
-5.19 4.24 4.04
-6.38 -1.74 1.43
4.08 1.30 5.33
6.27 0.93 -2.78];
beta = 0.01;
u1 = [1,1,1];
u2 = [-1,-1,-1];
u = [u1; u2];
% method 1
D1 = vpa(1 - exp(sym(-beta*pdist2(X,u).^2)));
[~, I1] = sort(D1, 2);
I1
% method 2
D2 = 1 - exp(sym(-beta*pdist2(X,u).^2));
[~, I2] = sort(D2, 2);
I2
I1 and I2 are different. The only difference is to use "vpa" or not.
How to solve this problem?
Thank you very much!
Answers (1)
David Hill
on 6 May 2022
Why are you using symbolics? Double should be sufficient (these are not large numbers).
D1 = (1 - exp(-beta*pdist2(X,u).^2));
[~, I1] = sort(D1, 2);
1 Comment
Songbai Jin
on 6 May 2022
Categories
Find more on Conversion Between Symbolic and Numeric in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!