number format inconsistency between '"format shortE" and "format default"
2 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
Stephen23
2024 年 10 月 15 日
編集済み: Stephen23
2024 年 10 月 15 日
"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
2024 年 10 月 15 日
"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)
回答 (0 件)
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!