Link to home
Start Free TrialLog in
Avatar of naseeam
naseeamFlag for United States of America

asked on

Why real part isn't zero?

Attached is Matlab command to convert polar form to rectangular form.  I'm converting 2e^j(pi/2) to rectangular form.

I was expecting real part to be 0 but it's a very small number.  Is this because there isn't enough bits to represent 0?
real_part_not_zero.PNG
ASKER CERTIFIED SOLUTION
Avatar of phoffric
phoffric

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of phoffric
phoffric

Welcome to the world of numerical analysis where numerical errors are the norm ( due to limited word length) and need to be analyzed; and when necessary, those small errors are corrected.
Phoffric is correct.  One cannot expect absolutely accurate results when dealing with real numbers on computers.  When zero is potentially involved and may affect results the code must check for this condition and say If (result .LE. 1.0E-24) then result = 0.0 (or whatever accuracy the calculation holds.)
Avatar of naseeam

ASKER

>> you have to normalize that Vector back to 1.0.
How do you normalize?
https://www.khanacademy.org/computing/computer-programming/programming-natural-simulations/programming-vectors/a/vector-magnitude-normalization

 If all you're concerned about is the magnitude of the vector and if it exceeds 1.0 , then one option is to simply set the lengths to 1.0 . But if you need to work with that unit vector , then you may reduce the X or Y coordinate by an amount epsilon and then verify that you get a unit length of 1.0 or a decimal point followed by many nines .
Avatar of naseeam

ASKER

Fast and good answers.

Thank you!