0

I have to calculate the angle of complex summations like

(exp(1i*0)+exp(1i*2*pi/3)+exp(1i*-2*pi/3))

which is equal to

(exp(1i*0)+exp(1i*2*pi/3)+exp(1i*4*pi/3))

but the results are different! because of the precision of exp matlab function.

ans =

   4.4409e-16


ans =

  -2.2204e-16 + 2.2204e-16i

the angle of the first one is zero but the second one result $3\pi/4$ which is wrong!

  • 3
    Use `vpa` if you have the symbolic math toolbox: `vpa('(exp(i*0)+exp(i*2*pi/3)+exp(i*4*pi/3))')` is exactly 0. – Andras Deak -- Слава Україні Jan 28 '16 at 03:10
  • 2
    `2.2204e-16` is the definition of `eps` in MATLAB. You might as well consider it to be 0. This is not an error. This is due to floating-point precision when evaluating functions whose output is "supposed" to be 0. – rayryeng Jan 28 '16 at 07:54
  • You could also consider to decompose your calculation to ```theta = (0 + 2/3 + 4/3)*pi; res = sin( theta )+1i*cos( theta );``` to reduce floating point errors. [Or even ```theta = (0 + 2 + 4)*pi/3;```] – Matthias W. Jan 28 '16 at 13:10
  • https://en.wikipedia.org/wiki/Double-precision_floating-point_format – patrik Jan 28 '16 at 15:24

0 Answers0