Difference between revisions of "Complex Numbers"
(Conj) |
|||
Line 32: | Line 32: | ||
To construct a complex number from its magnitude, ''A'', and phase in radians, ''r'', use <code>A * [[Exp]](r * 1j)</code>. Given a phase in degrees, ''d'', use <code>A * [[Exp]]([[Radians]](d) * 1j)</code>. | To construct a complex number from its magnitude, ''A'', and phase in radians, ''r'', use <code>A * [[Exp]](r * 1j)</code>. Given a phase in degrees, ''d'', use <code>A * [[Exp]]([[Radians]](d) * 1j)</code>. | ||
− | :<code>5 * [[Exp]]( 2.214j ) → -3 + 4j | + | :<code>5 * [[Exp]]( 2.214j )</code> → -3 + 4j |
+ | |||
+ | = Complex Conjugate = | ||
+ | |||
+ | The complex conjugate of a number is obtained as | ||
+ | :<code>[[Conj]](-3+4j)</code> → -3-4j | ||
+ | |||
+ | The conjugate transpose of a matrix is obtained using | ||
+ | :<code>[[Transpose]]([[Conj]](A),I,J)</code> | ||
= Arithmetic operations = | = Arithmetic operations = |
Revision as of 19:43, 2 July 2013
new to Analytica 4.5
Typing complex literals
A complex number has a real part and an imaginary part and is written like 3.4 + 2.3j, where 3.4 is the real part and 2.3 is the imaginary part. If there is no imaginary part, then it is a real number.
To type the imaginary part, append a lower case i or lower case j to the number. For example, 1i
or 1j
is the square root of -1. You must have a digit before the i or j, so you can't type just i -- that would refer to a variable named i. You also cannot put a space between the numbers and the i or j. Numeric suffixes come before the i or j, so you would write 3.4Kj
, 1.2mj
or 1.2e-3j
.
If you have a variable, x, that holds a complex number, and you want to use its value for the imaginary part, it does not work to type xj
-- that would refer to a variable named xj. You need to type x * 1j
.
Complex numbers display in result tables as the real part plus or minus the complex part, and using a small j after the complex part, e.g., -5 - 3j, 7.2 + 0.1j. The real and complex parts each use the prevailing number format.
When complex numbers appear on graphs, the real part is graphed. See Graphing below.
Precision and range
The real and imaginary parts of a complex number each have approximately 7 decimal digits of precision and can range from -3.4e+38 to 3.4e+38 and as small as 3.4e-38. This is less precision than is used for a real number in Analytica, which has roughly 15 decimal digits of precision and a range from -1.7e+308 to 1.7e+308, and down to 1.7e-308. One complex number takes up the same amount of memory as one real number (the complex number stores two 32-bit floats, whereas the a real number stores one 64-bit float).
Accessing the parts of a complex number
To extract the real or imaginary part of a complex number, as a real number, use RealPart(x)
or ImPart(x)
. For example
A complex number can also be written in polar form as [math]\displaystyle{ A e^{\theta j} }[/math], where A is the magnitude and [math]\displaystyle{ \theta }[/math] is the phase. To retrieve the magnitude use Abs(x)
. The phase can be extracted either in degrees or radians using ComplexDegrees(x)
or ComplexRadians(x)
.
Abs(-3+4j)
→ 5ComplexDegrees(-3+4j)
→ 126.9ComplexRadians(-3+4j)
→ 2.214
To construct a complex number from its magnitude, A, and phase in radians, r, use A * Exp(r * 1j)
. Given a phase in degrees, d, use A * Exp(Radians(d) * 1j)
.
5 * Exp( 2.214j )
→ -3 + 4j
Complex Conjugate
The complex conjugate of a number is obtained as
Conj(-3+4j)
→ -3-4j
The conjugate transpose of a matrix is obtained using
Arithmetic operations
The operations of +, -, * and / are standard from any textbook:
- [math]\displaystyle{ (a + b j) + (c + d j) = (a+c) + (b+d) j }[/math]
- [math]\displaystyle{ (a + b j) - (c + d j) = (a-c) + (b-d) j }[/math]
- [math]\displaystyle{ (a + b j) * (c + d j) = (ac - bd) + (bc + ad) j }[/math]
- [math]\displaystyle{ (a + b j) / (c + d j) = {{ac + bd}\over{c^2+d^2}} + {{bc-ad}\over{c^2+d^2}} j }[/math]
The conjugate of a complex number is RealPart(x) - 1j*ImPart(x)
.
For exponentiation (x^y
), involving two complex numbers, [math]\displaystyle{ x^y = \exp(y*\ln(x)) }[/math].
Degrees or radians?
Trigonometric functions in Analytica (Sin, Cos, ArcSin, etc) use degrees by convention. However, the functions Exp, Ln, and LogTen, when applied to a complex number, use radians. The convention that [math]\displaystyle{ e^{\pi j}=-1 }[/math] is highly standardized (if a degrees convention were used we would instead have [math]\displaystyle{ e^{180j}=-1 }[/math], which could get confusing fast). Thus, we have this identity for Analytica expressions.
Enabling complex numbers
If you attempt to evaluate Sqrt(-1)
, you'll be given a warning, and if you ignore warnings the result will be NaN. At least this is the case until you enable complex numbers. When
EnableComplexNumbers
is 0, built-in math functions operating on real numbers will warn and return NaN when the result would not be a real number. Built-in math functions will evaluate and return complex results without warnings when the parameter passed to them is complex. So, for example, Sqrt(4j)
returns 1.414+1.414j
even when EnableComplexNumbers
is 0.
To enable complex numbers, first make sure you do not have a node selected and that you are not in the middle of editing a definition, and make sure you are in edit mode. Then on the menus select Definition → System Variables → EnableComplexNumbers. The object window for EnableComplexNumbers will appear. Change the definition from 0 to 1.
The following functions are affected by this system variable: ArcCos, ArcCosH, ArcSin, Ln, Logit, LogTen, Sqrt, as well as the
x^y
operator.
Graphing
When you graph a value, x, which contains complex numbers, RealPart(x) is graphed and labeled as x. To get the imaginary part on the same graph, click the [XY] button at the top right, check Use another variable and press Add.... Select Library=Advanced Math then scroll down and select ImPart. In the parameter box, enter the name of the variable, which is x in this example and press OK twice. You might also want to go into Graph Setup... and check Swap horizontal and vertical and then select ImPart(x) as the vertical axis.
See Also
Accessing the parts of a complex number:
Non-matrix functions that compute or return complex numbers:
Matrix functions that handle complex matrices:
Enable comment auto-refresher