On Fri, Jul 01, 2022 at 06:48:28PM -0700, Eric Wheeler wrote:
> Thanks Ed and Luis!
>
> I've merged your responses, please see below inline:
> ...
>
> Luis Mochan wrote:
>
> > use v5.12;
> > use PDL;
> > use PDL::Constants qw(PI);
> > use PDL::IO::Misc;
> > # read all data, skip first row
> > my ($f, $M11, $A11, $M21, $A21, $M12, $A12, $M22, $A22)=rcols "rem.s2p", 
> > {LINES=>"1:-1:1"};
> > my $rows=$f->nelem;
> > my $M=pdl($M11, $M12, $M21, $M22); # Indices: filerow, position
> > my $R=pdl($A11, $A12, $A21, $A22)*PI/180; #   filerow, position
> > my $S=$M*exp(i()*$R); #                filerow, position
>
> Interesting that you used e^(i*theta) instead of cos and sin.  Is there a
> PDL performance benefit here, or just a simplified notation preference?

Just a simplified notation. My guess is that
    cos($R)+i()*sin($R)
would be faster, as the arguments are real (but I'm not certain).
>
> > my $Sm=$S->mv(0,-1) # position, filerow
> >       ->reshape(2,2, $rows); # column, row, filerow
> > say $f, $Sm, $Sm->info;
> >
> > rcols would read all the data into columns. For each row $M and $R would
> > have the magnitudes and the angles in radians, and $S would have the
> > corresponding complex numbers. Then, for each row I rearrange the four
> > corresponding $S's into a 2x2 matrix by first getting the row index
> > out of the way and then doing a reshape. I ran it with a file
>
> The code example is very useful and `rcols` could be very helpful to read
> in the data.
>
> I have the same question as above: correct me if I'm wrong, but it looks
> like you and Ed both produced a (2,2,n) matrix where n is the file row:

Right.

> If I take two such $S matrixes and do some operation like add or multiply,
> will it properly multiply each 2x2 complex matrix at each frequency
> assuming the frequencies are aligned in order?

Yes. You could do $Sm1 + $Sm2 or $Sm1 x $Sm2  where $Sm1 and $Sm2 have
the same structure as $Sm in my example, provided the number of 2x2
matrices (the number of file rows) is the same for both matrices (or
that one of them has exactly one 2x2 matrices), and
assuming that the interpretation of $MagS12 as the magnitude of the entry
$Sm(1,0,$row) in the first row (i=0) second column (j=1) of the matrix
is correct, and multiplication is defined in the usual algebraic way
(through the inner product of rows of the left hand operand with
columns of the right hand operand).

Best regards,
Luis



--

                                                                  o
W. Luis Mochán,                      | tel:(52)(777)329-1734     /<(*)
Instituto de Ciencias Físicas, UNAM  | fax:(52)(777)317-5388     `>/   /\
Av. Universidad s/n CP 62210         |                           (*)/\/  \
Cuernavaca, Morelos, México          | moc...@fis.unam.mx   /\_/\__/
GPG: 791EB9EB, C949 3F81 6D9B 1191 9A16  C2DF 5F0A C52B 791E B9EB


_______________________________________________
pdl-general mailing list
pdl-general@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/pdl-general

Reply via email to