Community Tip - Have a PTC product question you need answered fast? Chances are someone has asked it before. Learn about the community search. X
Hello,
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:
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. :
Solved! Go to Solution.
Here are Lucs functions modified for option 1 or option 2 as explained above. I would vote for option 1 (ignoring the zeros)
Here you go:
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
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?
There are three 'sign' functions: sign(), signum() and csgn(). Look them up in help.
Success!
Luc
Is it possible to skip the complex numbers in SignChanges and ChangeLocations functions if vector has both real numbers and complex numbers, and maintain in the counting only the real numbers?
@Cornel wrote:
Is it possible to skip the complex numbers in SignChanges and ChangeLocations functions if vector has both real numbers and complex numbers, and maintain in the counting only the real numbers?
Sure. Look at my ChangeLocations1() function where I trimmed the zeros and kept the original index positions. You can do similar by trimming the numbers with a non-zero imaginary part.
Adding this should do the job
Does have sense in the case of complex numbers to view sign changes?
Does it makes sense to count the sin changes in a series of real numbers?
YOU asked for a function to to do, so YOU should know how it makes sense for you and what for you would need that information.
According complex numbers - you would first have to clearly define what you would consider a "sign change" in the case of complex numbers.
@Werner_E wrote:
According complex numbers - you would first have to clearly define what you would consider a "sign change" in the case of complex numbers.
So, for the complex numbers I would consider a sign change in these 2 cases:
1. Re(z) will stay positive and Im(z) will change sign:
or
2. Re(z) will stay negative and Im(z) will change sign:
EDIT: But hold on a little with this complex numbers. I would need to think a little about these complex numbers, if it helps somehow or not. I will post if needed.
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?
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 😉
Here are Lucs functions modified for option 1 or option 2 as explained above. I would vote for option 1 (ignoring the zeros)
So, yes, we can treat all zeros as indifferent, and we can take the last positive/negative value for position.
So, yes, these (SignChanges1 and ChangeLocations1) seems better.
And for this, could be possible something like this for ChangeLocations1:
?
@LucMeekes
Is it possible to do like that?
Simply change the last assignment in my ChangeLocations1()
See if this helps:
It doesn't see the sign change from pos 1 to 2, but from pos 4 to 5 instead.
Remembering that you had a positive value 1 at pos 1 when you finally see a negative value -4 at pos 5 is possible, but more cumbersome.
And for a case with complex numbers:
Success!
Luc
In the last example, shouldn't the result be vector (0; 5) and not (4;5) ?
EDIT: Ah, sorry, I missed the fact that you had already addressed this issue yourself