Unexpected solution

I believe CVX is correctly optimizing the problem you provided it. I don’t know whether that’s the problem you intended to provide it.

The first version of your objective function, i.e. ,not the one provided to CVX, evaluates to a row vector (note that p/b evaluates to an x by x matrix) . I think when p or b have more than one non-zero element, the non-zero element (or the sum) of your first objective function does not equal your CVX objective. If p and b were both scalars, then your two objective functions wold be equal.

So your first step is to determine what you really want the objective function to be. Then make sure it is correctly modeled in CVX.