Skip to main content
19-Tanzanite
September 26, 2023
Solved

How to count sign changes in a vector/matrix and at what positions is there a sign change?

  • September 26, 2023
  • 2 replies
  • 3250 views

Hello,

Cornel_0-1695739655162.png

Cornel_1-1695739661242.png

Cornel_2-1695739671791.png

 

1. I would like to know how many sign changes there are in this vector viewed as a matrix.

There are 8 sign changes as far as we can see:

Cornel_3-1695739730688.png

So, here I would like a function that shows me 8 as output (the number 8 being the number of sign changes).

2. I would like a function that tells me that at column 0 and between lines 1 and 2 is a change of sign, that at column 0 and between lines 2 and 3 there is a change of sign, etc. :

Cornel_4-1695740199280.png

Best answer by Werner_E

Here are Lucs functions modified for option 1 or option 2 as explained above. I would vote for option 1 (ignoring the zeros)

Werner_E_0-1695769295118.png

 

2 replies

23-Emerald IV
September 26, 2023

Here you go:

LucMeekes_0-1695750683768.png

LucMeekes_1-1695750691529.png

Note that you have to supply the argument to the functions as an array, a vector to be specific. I abused an undocumented trick in the attached file: added an evaluation (=) to the end of the definition of the range.

 

Success!

Luc

 

Cornel19-TanzaniteAuthor
19-Tanzanite
September 27, 2023

@Werner_E 

 

How to think in the case of complex numbers? Does have sense in the case of complex numbers to view sign changes? Or is not possible for complex numbers this thing? Can be included also complex numbers in this counting of sign changes and locations?

Cornel_0-1695799361563.png

Cornel_1-1695799374662.png

Cornel_2-1695799386412.png

23-Emerald IV
September 27, 2023

There are three 'sign' functions: sign(), signum() and csgn(). Look them up in help.

Success!
Luc

25-Diamond I
September 26, 2023

How would you deal with a zero in the vector. Needs definition!

Lets say the vector is (3, 1, 0, 0, 0, -4. -5, 0, 0, -3)^T. How many sign changes and at which positions?

Werner_E_0-1695765953359.png

Basically I see two options:

 

Option 1:  If we treat zero as indifferent, neither pos nor neg, then I would say we have just one sign change (ignoring all zeros), but I could not say at which position - somewhere around 2,3,4? Maybe we say position 1 as being the last positive value?

 

Option 2:  If we treat zero as a third case of sign, then we would have 4 sign changes. probably at 1,4,6 and 8.

 

As usual in math its just a matter of definition 😉

 

Werner_E25-Diamond IAnswer
25-Diamond I
September 26, 2023

Here are Lucs functions modified for option 1 or option 2 as explained above. I would vote for option 1 (ignoring the zeros)

Werner_E_0-1695769295118.png

 

Cornel19-TanzaniteAuthor
19-Tanzanite
September 27, 2023

So, yes, we can treat all zeros as indifferent, and we can take the last positive/negative value for position.

Cornel_0-1695810343259.png

 

Cornel_5-1695810633723.png

 

Cornel_2-1695810404278.png

Cornel_3-1695810410505.png

So, yes, these (SignChanges1 and ChangeLocations1) seems better.

 

And for this, could be possible something like this for ChangeLocations1:

Cornel_7-1695810947207.png?

 

 

@LucMeekes 

Is it possible to do like that?

Cornel_3-1695809426149.png

Cornel_4-1695809432656.png

 

Cornel_8-1695811114523.png