Problems when sort 'sym' variables and 'vpa' double-precision number.
이전 댓글 표시
% 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!
답변 (1개)
David Hill
2022년 5월 6일
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);
카테고리
도움말 센터 및 File Exchange에서 Common Operations에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!