Quad_over_linear cost function and division by zero

My variables are q \in \mathbf{R}^N and A\in\mathbf{R}^N, where N is problem size.
I have a cost function to minimize, C=\sum_i^NA(i)^2/q(i) . There are some linear constraints which relate various variables. I have also enforced q(i)\geq0 and A(i)\geq 0 \:\: \forall i . I use quad_over_lin to compute the cost function.

Now the problem is formulated such that A(i)=0 should hold when q(i)=0. Is there an explicit way to make sure that the cost function term includes ith term only when q(i)\neq 0 ? The reason I am asking is that I think CVX is evaluating the term even when A(i)=0, and that is causing problems with convergence.

I get an solved/inaccurate message (it runs out of 10,000 iterations) and the value of cvx_status is ‘failed’. The cvx_optval is NAN. When I looked at the final q(i) values, the q(i) corresponding to A(i)=0 were all 0.

I also tried replacing the cost function with C=\sum_i^NA(i)^2/(\epsilon+q(i)) , where \epsilon is machine tolerance, but I end up getting same result, and now many $q(i)s are -\epsilon$, hence causing 0 in denominator again.

Any help will be appreciated.