Maybe rle can gelp get all sign changes, as in your second example:
pdl> $a=pdl[ 5.3332316, 4.3332316, 3.3332316, 2.3332316, 1.3332316,
0.33323163, -0.66676837, -1.6667684, -2.6667684, -3.6667684]
pdl> p $a
[ 5.3332316 4.3332316 3.3332316 2.3332316 1.3332316 0.33323163
-0.66676837 -1.6667684 -2.6667684 -3.6667684]
pdl> p $a<=>0
[1 1 1 1 1 1 -1 -1 -1 -1]
$a<=>0 is just the sign of the elements of $a
pdl> p +($a<=>0)->rle
[6 4] [1 -1]
which means there are 6 1's followed by 4 -1's
pdl> ($rle)=($a<=>0)->rle;
$rle has [6 4]
pdl> p $rle((0))-1
5
I choose the first sign change with ((0)) and subtract 1 to get the
index from the number of elements.
You can put everything together as in
pdl> p +[($a<=>0)->rle]->[0]->((0))-1
5
You could generalize this to get further resonances in more
complicated circuits.
Regards,
Luis
On Wed, Oct 05, 2022 at 06:50:32PM -0700, Eric Wheeler wrote:
> Hello all,
>
> I'm trying to find the series resonant frequency of an RF component, which
> is where the component reactance switches from positive to negtive or
> vice-versa.
>
> Given an N-vector PDL of sorted elements, I need to know at what index it
> switches from positive to negative.
>
> Here are some examples; in real life these are real values from physical
> measurements, so they are never going to be nice round integers---but you
> can assume they will be sorted in ascending or descending order.
>
> Example 1:
>
> pdl> p sequence(10)-5
> [-5 -4 -3 -2 -1 0 1 2 3 4]
> ^^
> I need to know "index 4" is the place at which it switches.
>
>
> Example 2:
>
> pdl> p ((-sequence(10))+5+rand())
> [ 5.3332316 4.3332316 3.3332316 2.3332316 1.3332316 0.33323163
> -0.66676837 -1.6667684 -2.6667684 -3.6667684]
> ^^^^^^^^^^
> In this floating-point example it would be "index 5"
>
>
> Is there already a "PDL-broadcast-way" of doing this?
>
> How would you do it?
>
> --
> Eric Wheeler
>
>
> _______________________________________________
> pdl-general mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/pdl-general
>
--
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 | [email protected] /\_/\__/
GPG: 791EB9EB, C949 3F81 6D9B 1191 9A16 C2DF 5F0A C52B 791E B9EB
_______________________________________________
pdl-general mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/pdl-general