| 1 |
// literal complex |
| 2 |
#(1,2) => complex foo; |
| 3 |
|
| 4 |
// declare a complex number |
| 5 |
complex bar; |
| 6 |
// set the real and imaginary parts |
| 7 |
-1 => bar.re; |
| 8 |
-2 => bar.im; |
| 9 |
|
| 10 |
// declare array |
| 11 |
complex array[2]; |
| 12 |
// set |
| 13 |
3 => array[0].re; |
| 14 |
4 => array[0].im; |
| 15 |
5 => array[1].re; |
| 16 |
6 => array[1].im; |
| 17 |
|
| 18 |
// sum |
| 19 |
complex sum; |
| 20 |
for( auto x : array ) |
| 21 |
{ |
| 22 |
sum + x => sum; |
| 23 |
} |
| 24 |
|
| 25 |
// re and im |
| 26 |
<<< foo.re, foo.im >>>; |
| 27 |
// print as complex |
| 28 |
<<< foo >>>; |
| 29 |
|
| 30 |
// mag and phase |
| 31 |
<<< (foo$polar).mag, (foo$polar).phase/pi >>>; |
| 32 |
// print as polar |
| 33 |
<<< foo$polar >>>; |
| 34 |
|
| 35 |
// print sum |
| 36 |
<<< sum >>>; |
| 37 |
|