A method I used in the past for a similar problem was:

- take the absolute value
- then get the index of the minimum value:

$indexno = $piddle->index(minimum_ind(abs($piddle))

There may be precision problems for very small piddles. You need a series of values that crosses zero only once.



Good luck

Hernán



Den 2022-10-06 kl. 04:53, skrev Luis Mochan:
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
pdl-general@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/pdl-general

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

Reply via email to