Programmer Guide/Command Reference/EVAL/complex arithmetic: Difference between revisions

From STX Wiki
Jump to navigationJump to search
mNo edit summary
 
(14 intermediate revisions by 3 users not shown)
Line 1: Line 1:
{{DISPLAYTITLE:complex arithmetic}}
{{DISPLAYTITLE:complex arithmetic}}__NOTOC__
__NOTOC__
Because the current version of the {{STX}} [[Programmer_Guide/Command_Reference/EVAL|EVAL command]] does not support a complex data type, a package of functions is used to implement arithmetic and special handling for [[#complex numerical objects|complex numbers]].
Because the current version of the {{STX}} [[Programmer_Guide/Command_Reference/EVAL|EVAL command]] does not support a complex data type, a package of functions is used to implement arithmetic and special handling for [[#complex numerical objects|complex numbers]].


The package consists of the following functions:  
The package consists of the following functions:  
:[[#complex->complex|cr2p, cp2r, conj]], [[#complex->real|cr2len, cr2phi, cget]], [[#real->complex|cset, conj]], [[#multiplication (element-wise)|cmul]], [[#special functions|ctrn, cdot, cmulv]]
:[[#complex → complex|cr2p, cp2r, conj]], [[#complex → real|cr2len, cr2phi, cget]], [[#real → complex|cset, conj]], [[#multiplication and division (element-wise)|cmul, cdiv]], [[#special functions|ctrn, cdot, cmulv]]


====complex numerical objects====
==complex numerical objects==
:* A complex number or complex scalar is a numerical object ''v'' with 2 rows and 1 column (a vector):
:* A complex number or complex scalar is a numerical object ''v'' with 2 rows and 1 column (a vector):
::{|class="keinrahmen"
::{|class="keinrahmen"
Line 28: Line 27:
|''v''[2*i+1,j] = || ''im''<sub>i,j</sub> or ''phi''<sub>i,j</sub>
|''v''[2*i+1,j] = || ''im''<sub>i,j</sub> or ''phi''<sub>i,j</sub>
|}
|}
:* In general a numerical object containing '''N x M''' complex numbers (N>=1, M>=1), consists of 2N rows and M columns, because each complex number uses two cells of a row.
:* In general a numerical object containing '''N x M''' complex numbers (N&ge;1, M&ge;1), consists of 2N rows and M columns, because each complex number uses two cells of a row.
:* If a numerical object containing '''N x M''' complex numbers, is converted element-wise to real, the resulting object consists of '''N x M''' real numbers.
:* If a numerical object containing '''N x M''' complex numbers, is converted element-wise to real, the resulting object consists of '''N x M''' real numbers.


====complex->complex====
==complex &rarr; complex==
:{|class="keinrahmen"
:{|class="keinrahmen"
|''xc'' ||... any complex type
|''xc'' ||... any complex type
Line 41: Line 40:
:;<code>''rc'' = '''conj'''(''xc'')</code>: Conjugate ''xc''; ''xc'' must be in cartesian format.
:;<code>''rc'' = '''conj'''(''xc'')</code>: Conjugate ''xc''; ''xc'' must be in cartesian format.


====complex->real====
==complex &rarr; real==
:{|class="keinrahmen"
:{|class="keinrahmen"
|''xc'' ||... any complex type
|''xc'' ||... any complex type
Line 52: Line 51:
:;<code>''r'' = '''cget'''(''xc'', 1)</code>: Get imaginary part or phase of ''xc'' (depends on format of ''xc'').
:;<code>''r'' = '''cget'''(''xc'', 1)</code>: Get imaginary part or phase of ''xc'' (depends on format of ''xc'').


====real->complex====
==real &rarr; complex==
:{|class="keinrahmen"
:{|class="keinrahmen"
|''x'' ||... any real type
|''x'' ||... any real type
Line 62: Line 61:
:;<code>''rc'' = '''cset'''(''x'', ''y'')</code>: Combine elements of ''x'' (real part or length) and ''y'' (imaginary part or phase) to complex numbers.
:;<code>''rc'' = '''cset'''(''x'', ''y'')</code>: Combine elements of ''x'' (real part or length) and ''y'' (imaginary part or phase) to complex numbers.


====multiplication (element-wise)====
==multiplication and division (element-wise)==
:{|class="keinrahmen"
:{|class="keinrahmen"
|''xc'' ||... any complex type (re,im)
|''xc'' ||... any complex type (re,im)
Line 77: Line 76:
:;<code>''rc'' = '''cmul'''(''xc'', ''yc'')</code>: Multiply ''xc'' and ''yc'' element by element.
:;<code>''rc'' = '''cmul'''(''xc'', ''yc'')</code>: Multiply ''xc'' and ''yc'' element by element.
::<code>''rc''<sub>i,j</sub> = ''xc''<sub>i,j</sub> * ''yc''<sub>i,j</sub></code>
::<code>''rc''<sub>i,j</sub> = ''xc''<sub>i,j</sub> * ''yc''<sub>i,j</sub></code>
:;<code>''rc'' = '''cdiv'''(''xc'')</code>: Compute the inverse of each element of ''xc''.
::<code>''rc''<sub>i,j</sub> = 1 / ''xc''<sub>i,j</sub></code>
:;<code>''rc'' = '''cdiv'''(''xc'', ''n'')</code>: Divide each element of ''xc'' by the complex number ''n''.
::<code>''rc''<sub>i,j</sub> = ''xc''<sub>i,j</sub> / ''n''</code>
:;<code>''rc'' = '''cdiv'''(''xc'', ''yc'')</code>: Divide ''xc'' by ''yc'' element by element.
::<code>''rc''<sub>i,j</sub> = ''xc''<sub>i,j</sub> / ''yc''<sub>i,j</sub></code>


====special functions====
==special functions==
:;<code>''rc''<sub>matrix</sub> = '''ctrn'''(''xc''<sub>matrix</sub>)</code>: Transposed the complex matrix ''xc''.
:;<code>''rc''<sub>matrix</sub> = '''ctrn'''(''xc''<sub>matrix</sub>)</code>: Transposed the complex matrix ''xc''.
::<code>''rc''<sub>i,j</sub> = ''xc''<sub>j,i</sub></code>
::<code>''rc''<sub>i,j</sub> = ''xc''<sub>j,i</sub></code>
Line 91: Line 96:
:;<code>''rc''<sub>matrix</sub> = '''cmulv'''(''xc''<sub>matrix</sub>, ''yc''<sub>matrix</sub>)</code>: Compute the product of the complex '''NxM''' matrix ''xc'' and the complex '''MxL''' matrix ''yc''. The result is the complex NxL matrix ''rc''.
:;<code>''rc''<sub>matrix</sub> = '''cmulv'''(''xc''<sub>matrix</sub>, ''yc''<sub>matrix</sub>)</code>: Compute the product of the complex '''NxM''' matrix ''xc'' and the complex '''MxL''' matrix ''yc''. The result is the complex NxL matrix ''rc''.
::<code>''rc''<sub>i,k</sub> = sum<sub>j=0..M-1</sub> (''xc''<sub>i,j</sub> * ''yc''<sub>j,i</sub>) , i=0..N-1 and k=0..L-1</code>
::<code>''rc''<sub>i,k</sub> = sum<sub>j=0..M-1</sub> (''xc''<sub>i,j</sub> * ''yc''<sub>j,i</sub>) , i=0..N-1 and k=0..L-1</code>
==See also==
:[[../#complex numbers|complex numbers]], [[../vvset|vvset]], [[../vvget|vvget]], [[../vv|vv]], [[../fft|fft]], [[../dft|dft]]


;See also: [[Programmer_Guide/Command_Reference/EVAL#complex numbers|complex numbers]], [[Programmer_Guide/Command_Reference/EVAL/vvset|vvset]], [[Programmer_Guide/Command_Reference/EVAL/vvget|vvget]], [[Programmer_Guide/Command_Reference/EVAL/vv|vv]], [[Programmer_Guide/Command_Reference/EVAL/fft|fft]], [[Programmer_Guide/Command_Reference/EVAL/dft|dft]],
[[../#Functions|<function list>]]
 
[[Programmer_Guide/Command_Reference/EVAL#Functions|<function list>]]

Latest revision as of 10:15, 2 May 2012

Because the current version of the STx EVAL command does not support a complex data type, a package of functions is used to implement arithmetic and special handling for complex numbers.

The package consists of the following functions:

cr2p, cp2r, conj, cr2len, cr2phi, cget, cset, conj, cmul, cdiv, ctrn, cdot, cmulv

complex numerical objects

  • A complex number or complex scalar is a numerical object v with 2 rows and 1 column (a vector):
v[0] = re (cartesian: real part) or len (polar: length)
v[1] = im (cartesian: imaginary part) or phi (polar: phase)
  • A complex vector with N elements is a numerical object v with 2N rows and 1 column (a vector):
v[2*i] = rei or leni
v[2*i+1] = imi or phii
  • A complex matrix with MxN elements is a numerical object v with 2N rows and M columns (a matrix):
v[2*i,j] = rei,j or leni,j
v[2*i+1,j] = imi,j or phii,j
  • In general a numerical object containing N x M complex numbers (N≥1, M≥1), consists of 2N rows and M columns, because each complex number uses two cells of a row.
  • If a numerical object containing N x M complex numbers, is converted element-wise to real, the resulting object consists of N x M real numbers.

complex → complex

xc ... any complex type
rc .. ... same complex type as xc
rc = cr2p(xc)
Convert xc from cartesian (real, imaginary) to polar (length, phase) format.
rc = cp2r(xc)
Convert xc from polar (length, phase) to cartesian (real, imaginary) format.
rc = conj(xc)
Conjugate xc; xc must be in cartesian format.

complex → real

xc ... any complex type
r ... same real type as xc
r = cr2len(xc)
Compute length of xc; xc is stored in cartesian format.
r = cr2phi(xc)
Compute phase of xc; xc is stored in cartesian format.
r = cget(xc, 0)
Get real part or length of xc (depends on format of xc).
r = cget(xc, 1)
Get imaginary part or phase of xc (depends on format of xc).

real → complex

x ... any real type
y ... same type as x
rc ... same complex type as x
rc = cset(x, y)
Combine elements of x (real part or length) and y (imaginary part or phase) to complex numbers.

multiplication and division (element-wise)

xc ... any complex type (re,im)
yc ... same complex type as 'xc'
n ... real or complex number (re,im)
result rc ... same complex type as xc
rc = cmul(xc, n)
rc = cmul(n, xc)
Multiply each element of xc with the real or complex number n.
rci,j = xci,j * n
rc = cmul(xc, yc)
Multiply xc and yc element by element.
rci,j = xci,j * yci,j
rc = cdiv(xc)
Compute the inverse of each element of xc.
rci,j = 1 / xci,j
rc = cdiv(xc, n)
Divide each element of xc by the complex number n.
rci,j = xci,j / n
rc = cdiv(xc, yc)
Divide xc by yc element by element.
rci,j = xci,j / yci,j

special functions

rcmatrix = ctrn(xcmatrix)
Transposed the complex matrix xc.
rci,j = xcj,i
rcscalar = cdot(xcvector, ycvector)
Compute the dot product (inner product) of the two complex vectors xc and yc (both with N elements).
rc = sumi=0..N-1 (xci * yci) , i=0..N-1
rcmatrix = cmulv(xcvector, ycvector)
Compute the tensor (or dyadic) product of the two complex vectors xc and yc.
rci,j = xci * ycj
rcvector = cmulv(xcvector, ycmatrix)
Compute the product of the complex vector xc (N elements) and the complex matrix yc (N rows, M columns).
rcj = sumi=0..N-1 (xci * yci,j) , j=0..M-1
rcvector = cmulv(xcmatrix, ycvector)
Compute the product of the complex matrix xc (N rows, M columns) and the complex vector yc (M elements).
rci = sumj=0..M-1 (xci,j * ycj) , i=0..N-1
rcmatrix = cmulv(xcmatrix, ycmatrix)
Compute the product of the complex NxM matrix xc and the complex MxL matrix yc. The result is the complex NxL matrix rc.
rci,k = sumj=0..M-1 (xci,j * ycj,i) , i=0..N-1 and k=0..L-1

See also

complex numbers, vvset, vvget, vv, fft, dft

<function list>

Navigation menu

Personal tools