Difference between revisions of "Complex Numbers"

 
(9 intermediate revisions by 2 users not shown)
Line 1: Line 1:
''new to [[Analytica 4.5]]''
+
[[Category: Number formats]]
  
= Typing complex literals =
+
== Enabling complex numbers ==
  
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 partIf there is no imaginary part, then it is a real number.
+
Complex numbers have a real part and an imaginary part e.g. <code>2 + 3j</code>, where <code>j</code> is the square root of -1.   
 +
Normally, if you attempt to evaluate <code>Sqrt(-1)</code>, you'll get a warning,
 +
and if you ignore warnings the result will be [[NaN]]. So first you must enable complex numbers.
  
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 jNumeric 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 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 &rarr; System Variables &rarr; EnableComplexNumbers'''. The object window for ''EnableComplexNumbers'' will appearChange the definition from 0 to 1.
  
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>.  
+
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, <code>Sqrt(4j)</code> returns <code>1.414+1.414j</code> even when [[EnableComplexNumbers]] is 0.
  
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.
+
These functions are affected by this system variable: [[ArcCos]], [[ArcCosH]], [[ArcSin]], [[Ln]], [[Logit]], [[LogTen]], [[Sqrt]], as well as the [[Exponentiation_of_negative_numbers|x^y]] operator.
  
When complex numbers appear on graphs, the real part is graphed.  See [[#Graphing|Graphing]] below.
+
== Typing complex literals ==
  
= Precision and range =
+
A complex number has a ''real part'' and an ''imaginary part'' and is written like <code>3.4 + 2.3j</code>, 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.
  
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-38This 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).
+
To type the imaginary part, append a lower case <code>i</code> or lower case <code>j</code> 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 <code>i</code> or <code>j</code>, so you can't type just <code>i</code> -- that would refer to a variable named <code>i</code>. You also cannot put a space between the numbers and the <code>i</code> or <code>j</code>Numeric suffixes come before the <code>i</code> or <code>j</code>, so you would write <code>3.4Kj</code>, <code>1.2mj</code> or <code>1.2e-3j</code>.  
  
= Accessing the parts of a complex number =
+
If you have a variable, <code>x</code>, 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 <code>xj</code>.  You need to type <code>x*1j</code>.
  
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>. For example
+
Complex numbers display in result tables as the real part plus or minus the complex part, and using a small <code>j</code> after the complex part, e.g., <code>-5 - 3j, 7.2 + 0.1j</code>. The real and complex parts each use the prevailing number format.
  
:<code>[[RealPart]](-3+4j)</code> &rarr; -3
+
When complex numbers appear on graphs, the real part is graphed.  See [[#Graphing|Graphing]] below.
:<code>[[ImPart]](-3+4j)</code> &rarr; 4
 
  
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>ComplexDegrees(x)</code> or <code>ComplexRadians(x)</code>.
+
== Precision and range ==
  
:<code>[[Abs]](-3+4j)</code> &rarr; 5
+
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).
:<code>[[ComplexDegrees]](-3+4j)</code> &rarr; 126.9
 
:<code>[[ComplexRadians]](-3+4j)</code> &rarr; 2.214
 
  
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>.
+
== Accessing the parts of a complex number ==
  
:<code>5 * [[Exp]]( 2.214j )</code> &rarr; -3 + 4j
+
To extract the real or imaginary part of a complex number, as a real number, use [[RealPart]](x) or [[ImPart]](x). For example
  
= Complex Conjugate =
+
:<code>RealPart(-3+4j) &rarr; -3</code>
 +
:<code>ImPart(-3+4j) &rarr; 4</code>
  
The complex conjugate of a number is obtained as
+
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 [[Abs]](x).  The phase can be extracted either in degrees or radians using [[ComplexDegrees]](x) or [[ComplexRadians]](x):.
:<code>[[Conj]](-3+4j)</code> &rarr; -3-4j
 
  
The conjugate transpose of a matrix is obtained using
+
:<code>Abs(-3+4j) &rarr; 5</code>
:<code>[[Transpose]]([[Conj]](A),I,J)</code>
+
:<code>ComplexDegrees(-3+4j) &rarr; 126.9</code>
 +
:<code>ComplexRadians(-3+4j) &rarr; 2.214</code>
  
= Arithmetic operations =
+
To construct a complex number from its magnitude, «A», and phase in radians, «r», use the [[Exp]] function in <code>A*Exp(r*1j)</code>.  Given a phase in degrees, «d», use <code>A*Exp(Radians(d)*1j)</code>.
  
The operations of +, -, * and / are standard from any textbook:
+
:<code>5*Exp(2.214j) &rarr; -3 + 4j</code>
* <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) - 1j*[[ImPart]](x)</code>.
+
== Complex Conjugate ==
  
For exponentiation (<code>x^y</code>), involving two complex numbers, <math>x^y = \exp(y*\ln(x))</math>
+
The complex conjugate of a number is obtained by [[Conj]] as
 +
:<code>Conj(-3+4j) &rarr; -3-4j</code>
  
= Degrees or radians? =
+
The conjugate transpose of a matrix is obtained by [[Transpose]] using
 +
:<code>Transpose(Conj(A), I, J)</code>
  
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>e^{\pi j}=-1</math> is highly standardized (if a degrees convention were used we would instead have <math>e^{180j}=-1</math>, which could get confusing fast).  Thus, we have this identity for Analytica expressions.
+
== Arithmetic operations ==
  
:<code>[[Exp]](1j*x) = [[Cos]]([[Degrees]](x)) + 1j * [[Sin]]([[Degrees]](x))</code>
+
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>
  
= Enabling complex numbers =
+
The conjugate of a complex number is <code>RealPart(x) - 1j*ImPart(x)</code>.
  
If you attempt to evaluate <code>[[Sqrt]](-1)</code>, 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 <code>EnableComplexNumbers</code> 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, <code>[[Sqrt]](4j)</code> returns <code>1.414+1.414j</code> even when <code>EnableComplexNumbers</code> is 0.
+
For exponentiation (<code>x^y</code>), involving two complex numbers, <math>x^y = \exp(y*\ln(x))</math>.
  
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 &rarr; System Variables &rarr; EnableComplexNumbers'''. The object window for ''EnableComplexNumbers'' will appear.  Change the definition from 0 to 1.
+
== Degrees or radians? ==
  
The following functions are affected by this system variable: [[ArcCos]], [[ArcCosH]], [[ArcSin]], [[Ln]], [[Logit]], [[LogTen]], [[Sqrt]], as well as the <code>x^y</code> operator.
+
[[Trig_Functions|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>e^{\pi j}=-1</math> is highly standardized (if a degrees convention were used we would instead have <math>e^{180j}=-1</math>, which could get confusing fast).  Thus, we have this identity for Analytica expressions.
  
= Graphing =
+
:<code>Exp(1j*x) = Cos(Degrees(x)) + 1j * Sin(Degrees(x))</code>
  
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.
+
== Graphing ==
  
= Comparisons and ordering =
+
When you graph a value, <code>x</code>, which contains complex numbers, [[RealPart]](x) is graphed and labeled as <code>x</code>. 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 <code>x</code> 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.
  
The = and <> operators can be used to detect whether two complex numbers are equal or not-equal.
+
== Comparisons and ordering ==
 +
The [[Comparison_Operators|comparison operators]] = and <> can be used to detect whether two complex numbers are equal or not-equal.
  
 
Ordering comparisons (<, >, <=, >=) cannot be applied to non-equal complex numbers.  If you attempt to do so, a warning is issued and the result (if you ignore warnings) is [[NaN]]. Any system that imposes even a partial order on complex numbers runs into logical contradictions.  For example, if you were to assert that <code>0 < 1j</code>, then by squaring each side you get <code>0 < -1</code>, a contradiction.  
 
Ordering comparisons (<, >, <=, >=) cannot be applied to non-equal complex numbers.  If you attempt to do so, a warning is issued and the result (if you ignore warnings) is [[NaN]]. Any system that imposes even a partial order on complex numbers runs into logical contradictions.  For example, if you were to assert that <code>0 < 1j</code>, then by squaring each side you get <code>0 < -1</code>, a contradiction.  
Line 80: Line 83:
 
You can apply the sorting functions ([[SortIndex]], [[Rank]] and [[Sort]]) to arrays of complex numbers. For this purpose and arbitrary total ordering is imposed ([[RealPart]] compared first, in the event of a tie, [[ImPart]] is used) so that the sort can be carried out.  Functions [[Max]] and [[Min]] return the first value among incomparable items.
 
You can apply the sorting functions ([[SortIndex]], [[Rank]] and [[Sort]]) to arrays of complex numbers. For this purpose and arbitrary total ordering is imposed ([[RealPart]] compared first, in the event of a tie, [[ImPart]] is used) so that the sort can be carried out.  Functions [[Max]] and [[Min]] return the first value among incomparable items.
  
= See Also =
+
== History ==
 +
New in [[Analytica 4.5]].
  
 +
== See Also ==
 +
* [[Pi]]
 +
* [[Complex number functions]]
 +
* [[EnableComplexNumbers]]
 
Accessing the parts of a complex number:
 
Accessing the parts of a complex number:
* [[RealPart]], [[ImPart]], [[Abs]], [[ComplexDegrees]], [[ComplexRadians]]
+
* [[RealPart]], [[ImPart]], [[Abs]], [[Conj]], [[ComplexDegrees]], [[ComplexRadians]]
 
Non-matrix functions that compute or return complex numbers:
 
Non-matrix functions that compute or return complex numbers:
 
* [[Sqrt]], [[Sqr]], [[Ln]], [[LogTen]], [[Exp]]
 
* [[Sqrt]], [[Sqr]], [[Ln]], [[LogTen]], [[Exp]]

Latest revision as of 20:09, 18 March 2016


Enabling complex numbers

Complex numbers have a real part and an imaginary part e.g. 2 + 3j, where j is the square root of -1. Normally, if you attempt to evaluate Sqrt(-1), you'll get a warning, and if you ignore warnings the result will be NaN. So first you must enable complex numbers.

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.

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.

These functions are affected by this system variable: ArcCos, ArcCosH, ArcSin, Ln, Logit, LogTen, Sqrt, as well as the x^y operator.

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

RealPart(-3+4j) → -3
ImPart(-3+4j) → 4

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) → 5
ComplexDegrees(-3+4j) → 126.9
ComplexRadians(-3+4j) → 2.214

To construct a complex number from its magnitude, «A», and phase in radians, «r», use the Exp function in 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 by Conj as

Conj(-3+4j) → -3-4j

The conjugate transpose of a matrix is obtained by Transpose using

Transpose(Conj(A), I, J)

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.

Exp(1j*x) = Cos(Degrees(x)) + 1j * Sin(Degrees(x))

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.

Comparisons and ordering

The comparison operators = and <> can be used to detect whether two complex numbers are equal or not-equal.

Ordering comparisons (<, >, <=, >=) cannot be applied to non-equal complex numbers. If you attempt to do so, a warning is issued and the result (if you ignore warnings) is NaN. Any system that imposes even a partial order on complex numbers runs into logical contradictions. For example, if you were to assert that 0 < 1j, then by squaring each side you get 0 < -1, a contradiction.

You can apply the sorting functions (SortIndex, Rank and Sort) to arrays of complex numbers. For this purpose and arbitrary total ordering is imposed (RealPart compared first, in the event of a tie, ImPart is used) so that the sort can be carried out. Functions Max and Min return the first value among incomparable items.

History

New in Analytica 4.5.

See Also

Accessing the parts of a complex number:

Non-matrix functions that compute or return complex numbers:

Matrix functions that handle complex matrices:

Comments


You are not allowed to post comments.