I have an array of length M. The elements of the array are either zero or positive real numbers. I need to derive a function/analytic expression (preferably linear/convex/concave) that finds the index of the first positive element of the array.

Example: Let p denote the desired array and let p = [0 0 0.3 2.6 0 0 1.1 0 1.8 0]

Here, the first positive element is 0.3 and its index is 3. I need an analytic expression that gives me this index, i.e., 3.

Previous work: I have already derived an expression for arrays that contain only binary numbers.

Let x denote the desired vector and x = [0 0 1 1 0 0 1 0 1 0].

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. The following expression (written in Latex format) finds the index of the first positive element of this array.

min_{m \in M} (m * x_m + |M| (1 - x_m))

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

= 3.

This function is concave and it provides the correct answer. Unfortunately, it only works for arrays that contain binary numbers!

I want to find an expression that works for arrays with real numbers (like array p). This function will become a constraint in my optimization problem. Hence, convexity/concavity is desired. However, any analytic expression that gives the index of the first positive element will help.

Any feedback will be appreciated.




It seems the following.

You can simply define the expression for the required function $f$. For this simply replace each “x_i” in the function for binary array by “sign x_i”. From the other side, such the function $f$ is unique, and therefore its linearity or convexity does not depend of the form of its analytic expression, and you can easily check that the function $f$ is convex, because for any arrays $x,y$ such that $f(x)\le f(y)$ and $\lambda\in (0,1]$ we have that $f(\lambda x+(1-\lambda)y)=f(x)\le \lambda f(x)+(1-\lambda)f(y)$.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.