number format inconsistency between '"format shortE" and "format default"
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Why does using "format shortE" gives incorrect value for X? X should just be a identity
lambda= [3*1i 0;0 3*1i]
K = diag(2*pi*lambda)
L = exp(K)
X = diag(L)
format shortE
lambda= [3*1i 0;0 3*1i]
K = diag(2*pi*lambda)
L = exp(K)
X = diag(L)
2 Kommentare
Stephen23
am 15 Okt. 2024
Bearbeitet: Stephen23
am 15 Okt. 2024
"X should just be a identity"
I would not necessarily expect that result when performing numeric calculations. Numeric calculations are definitely not symbolic/algebraic mathematics.
"Why does using "format shortE" gives incorrect value for X?"
This has nothing to do with the FORMAT, the values are most likely not "incorrect". What is much more likely is that you have not taken into account the behaviors of binary floating point mathematics, in particular the accumulation of floating point error during e.g. the EXP operation.
lambda = [3*1i 0;0 3*1i];
K = diag(2*pi*lambda);
L = exp(K);
X = diag(L);
real(X)
imag(X) % not zero
Using (slower) symbolic mathematics:
K = diag(2*sym(pi)*lambda);
L = exp(K);
X = diag(L)
Stephen23
am 15 Okt. 2024
"Every operation will accumulate some floating point error which is why decimal point precision needs to be reduced in each step according to the order of error in each step."
Variable precision is not a requirement of IEEE 754: https://en.wikipedia.org/wiki/IEEE_754
"So I guess the question becomes is how to tell MATLAB to take the order of error into account to give the end result with respect to a given precision of PI or EXP."
lambda = [3*1i 0;0 3*1i];
K = diag(2*pi*lambda);
L = round(exp(K),9);
X = diag(L)
Antworten (0)
Siehe auch
Kategorien
Mehr zu Logical finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!