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

4 Ansichten (letzte 30 Tage)
Songbai Jin
Songbai Jin am 27 Apr. 2022
Kommentiert: Songbai Jin am 6 Mai 2022
% 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!

Antworten (1)

David Hill
David Hill am 6 Mai 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 Kommentar
Songbai Jin
Songbai Jin am 6 Mai 2022
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.

Melden Sie sich an, um zu kommentieren.

Tags

Produkte


Version

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by