Difference between revisions of "Complex Numbers"
(Start of draft) |
|||
Line 7: | Line 7: | ||
To type the imaginary part, append a lower case i or lower case j to the number. For example, <code>1i</code> or <code>1j</code> 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 <code>3.4Kj</code>, <code>1.2mj</code> or <code>1.2e-3j</code>. | To type the imaginary part, append a lower case i or lower case j to the number. For example, <code>1i</code> or <code>1j</code> 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 <code>3.4Kj</code>, <code>1.2mj</code> or <code>1.2e-3j</code>. | ||
− | 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 <code>xj</code> -- that would refer to a variable named ''xj''. You need to type <code>x * 1j<code>. | + | 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 <code>xj</code> -- that would refer to a variable named ''xj''. You need to type <code>x * 1j</code>. |
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. | 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. | ||
Line 18: | Line 18: | ||
= Accessing the parts of a complex number = | = Accessing the parts of a complex number = | ||
+ | |||
+ | To extract the real or imaginary part of a complex number, as a real number, use <code>RealPart(x)</code> or <code>ImPart(x)</code>. | ||
+ | |||
+ | A complex number can also be written in polar form as <math>A e^{\theta j}</math>, where ''A'' is the ''magnitude'' and <math>\theta</math> is the ''phase''. To retrieve the magnitude use <code>[[Abs]](x)</code>. The phase can be extracted either in degrees or radians using <code>DegreesPart(x)</code> or <code>RadiansPart(x)</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>. | ||
= Arithmetic operations = | = Arithmetic operations = | ||
+ | |||
+ | The operations of +, -, * and / are standard from any textbook: | ||
+ | * <math>(a + b j) + (c + d j) = (a+c) + (b+d) j</math> | ||
+ | * <math>(a + b j) - (c + d j) = (a-c) + (b-d) j</math> | ||
+ | * <math>(a + b j) * (c + d j) = (ac - bd) + (bc + ad) j</math> | ||
+ | * <math>(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 <code>[[RealPart]](x) - [[ImPart]](x)</code>. | ||
+ | |||
+ | Exponentiation is trickier. It is, of course, the case that <code>1j^2</code> is -1. But the case where a complex number is raised to a complex power is not at all straightforward. ''Need to write this part..'' | ||
+ | |||
+ | |||
+ | |||
+ | = Degrees or radians? == | ||
= Enabling complex numbers = | = Enabling complex numbers = |
Revision as of 01:00, 11 April 2013
new to Analytica 4.5
Typing complex literals
A complex number has a real part and an imaginary part and is written as, e.g., 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)
.
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 DegreesPart(x)
or RadiansPart(x)
.
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)
.
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) - ImPart(x)
.
Exponentiation is trickier. It is, of course, the case that 1j^2
is -1. But the case where a complex number is raised to a complex power is not at all straightforward. Need to write this part..
Degrees or radians? =
Enabling complex numbers
Graphing
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