You didn't really show us what you've tried and how it's failing, so about the best we can do is demonstrate some techniques for creating a list of complex numbers given some input list. Here are a few:
use strict; use warnings; use feature 'say'; use Math::Complex; my @array = map {cplx($_->[0], $_->[1])} ( [1, 8], [2, 5], [6, 4], ); say for @array;
The output will be:
1+8i 2+5i 6+4i
You could also use List::Util's pairmap:
use strict; use warnings; use feature 'say'; use Math::Complex; use List::Util 'pairmap'; my @array = pairmap {cplx($a, $b)} (1, 8, 2, 5, 6, 4); say for @array;
This produces the same output.
Per the documentation for Math::Complex, cplx() is approximately synonymous with Math::Complex->make(), so this would also work:
use strict; use warnings; use feature 'say'; use Math::Complex; my @array; push @array, Math::Complex->make($_->[0], $_->[1]) for ([1,8], [2,5], [6,4]); say for @array;
And the output will be the same.
Dave
In reply to Re: array of complex numbers
by davido
in thread array of complex numbers
by pmccarthy
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |