Problems when sort 'sym' variables and 'vpa' double-precision number.

조회 수: 1 (최근 30일)
Songbai Jin
Songbai Jin 2022년 4월 27일
댓글: Songbai Jin 2022년 5월 6일
% 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
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);
  댓글 수: 1
Songbai Jin
Songbai Jin 2022년 5월 6일
Thank you for your reply!
In fact, initially I set beta=100, and I noticed that all numbers in my distance matrix D is 1.
I tried to use 'sym' to improve accuracy, however, I noticed even a small beta (like 0.01) led to a wrong sort result.
I'd really appreciate it if you could help solve my confusion.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Numbers and Precision에 대해 자세히 알아보기

태그

제품


릴리스

R2020b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by