How do I separate the real and imaginary parts of a complex number in Lua?
If x represents some complex-valued number in Lua, you can get the real and imaginary parts with the built-in functions re(x) and im(x), respectively. Other useful built-in functions for manipulating complex numbers are: abs(x) Returns the magnitude of complex number x arg(x) Returns the argument of complex number x in radians (essentially the same as atan2(im(x),re(x))) conj(x) Returns the complex conjugate of complex number x. All built-in math functions should give the correct results for complex-valued arguments. It is also important to note that in FEMM’s implementation of Lua, sqrt(-1) is represented by the uppercase I. When representing complex numbers, always multiply by I. For example, the complex number 100*I is valid, but 100I would give an error. If you ask Lua to print out a complex number, that number will follow the same convention.
Related Questions
- What do I do when a student with a disability asks me to provide extra time for her examinations or to arrange for a separate, quiet room in which to take them?
- Depending on how I call sqrt(), I get different signs for the imaginary part of the square root of a complex number. Whats the reason for this?
- when complex numbers are plotted on graph why the Y axis is called imaginary part?