Programmer Guide/Command Reference/EVAL/complex arithmetic: Difference between revisions
From STX Wiki
< Programmer Guide | Command Reference | EVAL
Jump to navigationJump to search
No edit summary |
No edit summary |
||
Line 5: | Line 5: | ||
* 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. | * 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 numbers, the resulting object consists of N rows and M columns. | * If a numerical object containing '''N x M''' complex numbers, is converted element-wise to real numbers, the resulting object consists of N rows and M columns. | ||
---- | |||
;complex -> complex: | ;complex -> complex: | ||
:{|class="einrahmen" | :{|class="einrahmen" | ||
Line 17: | Line 17: | ||
:;<code>''rc''=cp2r(''xc'')</code>: Convert ''xc'' from polar (length, phase) to cartesian (real, imaginary) format. | :;<code>''rc''=cp2r(''xc'')</code>: Convert ''xc'' from polar (length, phase) to cartesian (real, imaginary) format. | ||
:;<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 -> real: | ||
:{|class="einrahmen" | :{|class="einrahmen" | ||
Line 26: | Line 26: | ||
| same '''real''' type as ''xc'' | | same '''real''' type as ''xc'' | ||
|} | |} | ||
:;<code>''r''=cr2len(''xc''): Compute length of ''xc''; ''xc'' is stored in cartesian format. | :;<code>''r''=cr2len(''xc'')</code>: Compute length of ''xc''; ''xc'' is stored in cartesian format. | ||
:;<code>''r''=cr2phi(''xc'')</code>: Compute phase of ''xc''; ''xc'' is stored in cartesian format. | :;<code>''r''=cr2phi(''xc'')</code>: Compute phase of ''xc''; ''xc'' is stored in cartesian format. | ||
:;<code>''r''=cget(''xc'',0)</code>: Get real part or length of ''xc'' (depends on format of ''xc''). | :;<code>''r''=cget(''xc'',0)</code>: Get real part or length 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''). | :;<code>''r''=cget(''xc'',1)</code>: Get imaginary part or phase of ''xc'' (depends on format of ''xc''). | ||
---- | |||
;real -> complex: | ;real -> complex: | ||
:{|class="einrahmen" | :{|class="einrahmen" | ||
Line 43: | Line 43: | ||
|} | |} | ||
:;<code>''rc''=cset(''x'',''y'')</code>: Combine elements of ''x'' (real part or length) and ''y'' (imaginary part or phase) to a complex numbers | :;<code>''rc''=cset(''x'',''y'')</code>: Combine elements of ''x'' (real part or length) and ''y'' (imaginary part or phase) to a complex numbers | ||
---- | |||
;multiplication (element-wise) | ;multiplication (element-wise) | ||
:{|class="einrahmen" | :{|class="einrahmen" | ||
Line 60: | Line 60: | ||
:;<code>''rc''=cmul(''xc'',''n'')</code> | :;<code>''rc''=cmul(''xc'',''n'')</code> | ||
:;<code>''rc''=cmul(''n'',''xc'')</code>: Multiply each element of ''xc'' with the real or complex number ''n''. | :;<code>''rc''=cmul(''n'',''xc'')</code>: Multiply each element of ''xc'' with the real or complex number ''n''. | ||
::<code>''rc''<sub>i,j</sub> = ''xc''<sub>i,j</sub> * ''n''</code> | |||
:;<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> | |||
---- | |||
;vector and matrix multiplication: | ;vector and matrix multiplication: | ||
:;<code>''rc''<sub>matrix</sub>=cmulv(''xc''<sub>vector</sub>,''yc''<sub>vector</sub>)</code>: Compute the tensor (or dyadic) product of the two complex vectors ''xc'' and ''yc'': | :;<code>''rc''<sub>matrix</sub>=cmulv(''xc''<sub>vector</sub>,''yc''<sub>vector</sub>)</code>: Compute the tensor (or dyadic) product of the two complex vectors ''xc'' and ''yc'': | ||
Line 71: | Line 73: | ||
:;<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> | ||
---- | |||
;special functions | ;special functions | ||
:;<code>''rc''=cdot(''xc'',''yc'')</code>: the result ''rc'' (complex number) is the dot product of the complex vectors ''xc'' and ''yc'' | :;<code>''rc''=cdot(''xc'',''yc'')</code>: the result ''rc'' (complex number) is the dot product of the complex vectors ''xc'' and ''yc'' |
Revision as of 14:10, 7 April 2011
Because the current version of the STx EVAL command do not support a complex data type, a package of functions is used to implement arithmetic and special handling for complex numbers.
Note:
- 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 numbers, the resulting object consists of N rows and M columns.
- complex -> complex
argument xc any complex type result 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
argument xc any complex type result 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
argument x any real type argument y same type as x result 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 a complex numbers
- multiplication (element-wise)
argument xc any complex type (re,im) argument yc same type as 'xc' argument n a 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
- vector and matrix multiplication
-
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
- special functions
-
rc=cdot(xc,yc)
- the result rc (complex number) is the dot product of the complex vectors xc and yc
rc=ctrn(xc)
- the result rc is transposed matrix of the complex matrix xc
- See also
- fft, complex numbers