Is this a logical Error in Matlab ? exp (pi*i*6) = 1.000000000000000 - 0.000000000000001i. WHY an i component ?, should just be 1
古いコメントを表示
Is this a Logical Error in Matlab ?
exp (pi*i*6) = 1.000000000000000 - 0.000000000000001i.
WHY an i component ?, shouldnt the answer just be 1?
Please answer.
1 件のコメント
"Is this a Logical Error in Matlab ?"
Probably not.
"WHY an i component ?, shouldnt the answer just be 1?"
The answer may be exactly one if you are doing algebraic/symbolic mathematics:
exp(sym(pi)*i*6)
But you did not tell your computer to do symbolic mathematics, you gave it a numeric task using numeric operations. All numeric operations have precision limited by their data types, take finite speed, have finite domains of validity. And when working with binary floating point numbers they easily accumulate floating point error.
The only "logical error" here is assuming that your computer has infinite precision when doing numeric calculations.
採用された回答
その他の回答 (2 件)
πis a transcendental number. pi is the double precision approximation to that number. There are some functions in MATLAB that let you operate as though you were using πinstead of pi (like sinpi and cospi) but exp is not one of them.
So if you wanted to compute this without the roundoff error caused by using pi instead of π, you could use the identity
.
.format longg
y = [exp(6i*pi); ...
cos(6*pi)+1i*sin(6*pi); ...
cospi(6)+1i*sinpi(6)]
It is all about a display format:
format short
exp(pi*i*6)
% compare with this:
cos(6*pi)+1i*sin(6*pi)
% Compare this:
format long
[exp(pi*1i*6); cos(6*pi)+1i*sin(6*pi)]
カテゴリ
ヘルプ センター および File Exchange で Assumptions についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!