Analytic expression to find the range of non-negative numbers in array

In summary: Hope this clarifies things. Thank you.In summary, the goal is to find the span of indices for which the elements of an array are positive. This is different from finding the number of positive elements in an array. The desired result is the difference between the rightmost and leftmost index for which the element is positive. An analytic expression is needed for this, preferably linear or convex, for arrays with real numbers.
  • #1
nazmul.islam
2
0
Hello,

I have an array of length M. Some of the indices are non-negative. I need to derive a function/analytic expression (preferably linear or convex) that finds the span of indices for which the indices are non-negative.

Example: Let p denote the desired vector.

Let, p = [0 0 0.3 2.6 0 0 1.1 0 1.8 0]

There are 10 elements in the array. Non-negative numbers start from index 3 (0.3) and end at index 9 (1.8). Range/span of non-negative numbers = 9-3+1 = 7.

I need a linear/convex function/analytic expression that can find this number.

Previous work:

I have already derived a similar function if the array only contains binary numbers.

Example: let, x = [0 0 1 1 0 0 1 0 1 0].

Now, let M denote the set of indices of x, i.e., M = {1,2,3,...,10}. Assume that x_m denotes the
m-th entry of the array x. For example, x_2 = 0, x_3 = 1. Here, |M| = 10.

My derived function (written in Latex format),
f(x) = max_{m \in M} (m * x_m) - min_{m \in M} (m * x_m + |M| (1 - x_m)) + 1

= max (1 * x_1, 2 * x_2, ..) - min (1 * x_1 + 10 * (1 - x_1), 2 * x_2 + 10 * (1 - x_2), ...) + 1

= 9 - 3 + 1

= 7.

This function is convex and it provides the correct answer. However, it only works for arrays that consist of binary numbers.

I need to find a linear/convex function/analytic expressions which work for arrays that consist of any non-negative number. This function will go into a constraint of my optimization problem. Hence, linearity/convexity is required. However, even a non-linear/non-convex function may help me, too.

Any ideas? Thanks a lot for reading this message. Let me know if I should post it in a different sub-forum of the math forum.

Thanks,

Nazmul
 
Physics news on Phys.org
  • #2
nazmul.islam said:
Hello,

I have an array of length M. Some of the indices are non-negative.
No. Based on what you have said below, all indexes are positive (1, 2, 3, etc.). Also, no elements of your array are negative, but some of them are zero. It might be a language translation problem. Nonnegative means "not negative" and includes numbers that are either zero or positive.
nazmul.islam said:
I need to derive a function/analytic expression (preferably linear or convex) that finds the span of indices for which the indices are non-negative.
Based on your example, what you're looking for is a function that finds the number of elements that are positive.
nazmul.islam said:
Example: Let p denote the desired vector.

Let, p = [0 0 0.3 2.6 0 0 1.1 0 1.8 0]

There are 10 elements in the array. Non-negative numbers start from index 3 (0.3) and end at index 9 (1.8). Range/span of non-negative numbers = 9-3+1 = 7.
All elements in your array are nonnegative. Some elements are zero and the rest are positive.

Pretty much any programming language can be used to write a simple function that returns the number of positive elements in an array.

In C, the code would look like this:

Code:
int positiveElements(float arr[], int count)
{
  int i;
  int numPos = 0;

  if (count != 0) 
  {
    for (int i = 0; i < count; i++)
    {
      if (arr[i] > 0) numPos++;
    }
  }
  return numPos;
}
nazmul.islam said:
I need a linear/convex function/analytic expression that can find this number.

Previous work:

I have already derived a similar function if the array only contains binary numbers.

Example: let, x = [0 0 1 1 0 0 1 0 1 0].

Now, let M denote the set of indices of x, i.e., M = {1,2,3,...,10}. Assume that x_m denotes the
m-th entry of the array x. For example, x_2 = 0, x_3 = 1. Here, |M| = 10.

My derived function (written in Latex format),
f(x) = max_{m \in M} (m * x_m) - min_{m \in M} (m * x_m + |M| (1 - x_m)) + 1

= max (1 * x_1, 2 * x_2, ..) - min (1 * x_1 + 10 * (1 - x_1), 2 * x_2 + 10 * (1 - x_2), ...) + 1

= 9 - 3 + 1

= 7.

This function is convex and it provides the correct answer. However, it only works for arrays that consist of binary numbers.

I need to find a linear/convex function/analytic expressions which work for arrays that consist of any non-negative number. This function will go into a constraint of my optimization problem. Hence, linearity/convexity is required. However, even a non-linear/non-convex function may help me, too.

Any ideas? Thanks a lot for reading this message. Let me know if I should post it in a different sub-forum of the math forum.

Thanks,

Nazmul
 
  • #3
Hello Mark44,

Thanks for your reply. I appreciate your effort.

Actually, I probably confused readers by mentioning "non-negative indices". Ideally, I want to find the SPAN of indices that correspond to the "positive elements" in an array. Note that, it is not equal to the number of "positive elements" in an array.

For example, let p = [0 0 0.3 2.6 0 0 1.1 0 1.8 0].

Here, there are 4 positive elements in the array (0.3, 2.6, 1.1, 1.8). However, I want to find the span of indices for which the elements are positive, i.e., the difference between the rightmost and leftmost index for which the element is positive.

In this case, the leftmost index is 3 (corresponding value of the element is 0.3). The rightmost index is 9 (corresponding value of the element is 1.8). Hence, the span is, 9-3+1 = 7.

I know how to find this "span" using a C code. I just need to find an analytic expression that can find this expression when the vector is given.

I have already derived an analytic expression when the elements are binary (shown in my original post). I need to derive an expression where the elements of the vectors are real numbers.
 

Related to Analytic expression to find the range of non-negative numbers in array

1. What is an "analytic expression"?

An analytic expression is a mathematical formula or equation that can be used to solve a problem or calculate a value.

2. How is the range of non-negative numbers in an array determined?

The range of non-negative numbers in an array is determined by finding the largest and smallest values in the array and subtracting them from each other.

3. Can the range of non-negative numbers be negative?

No, the range of non-negative numbers can only be positive or zero, as it is the difference between the largest and smallest non-negative values in an array.

4. What is the significance of finding the range of non-negative numbers in an array?

Finding the range of non-negative numbers in an array can help in understanding the spread or distribution of the data. It can also be useful in identifying outliers or extreme values in the data set.

5. Are there any limitations to using an analytic expression to find the range of non-negative numbers in an array?

One limitation is that an analytic expression may not be able to handle large or complex arrays. It also assumes that the array contains only non-negative numbers, so it may not be suitable for arrays with a mix of positive and negative numbers.

Similar threads

  • Linear and Abstract Algebra
Replies
1
Views
938
  • Engineering and Comp Sci Homework Help
Replies
21
Views
2K
  • Programming and Computer Science
Replies
17
Views
2K
Replies
3
Views
758
  • Precalculus Mathematics Homework Help
Replies
15
Views
665
  • Precalculus Mathematics Homework Help
Replies
32
Views
866
  • Programming and Computer Science
Replies
13
Views
3K
  • Programming and Computer Science
Replies
3
Views
862
  • Precalculus Mathematics Homework Help
Replies
7
Views
766
Replies
16
Views
2K
Back
Top