Different scaling gives vastly different solutions

This problem has to do with proper scaling (again) of an LP.

It seems like CVX is extremely sensitive to different scaling. I provide example code which happens to mimic my own problem to illustrate the issue. Note that I have checked the condition number and it should be considered low already (<10).

The tall matrix C included as part of the optimization problem (Cx<=b) is full column rank. Note that it is random since I need to perform Monte Carlo simulations.

The wanted order of magnitude for the largest matrix element can be changed with a parameter (wantedPowerOf10) in the example code. Please note that the optimization variables model power, so the solution should not be negative (though it sometimes does, and I am not sure how to deal with this).

Please advise. Your help is utmost appreciated. Thank you.

Edit:
% ---------------------------------------------------
clear all

n = 3; m = 5;

% Lower and upper bounds on opt. variables
bMax = 0.1;
b = bMaxones(m,1);
l = zeros(n,1);
u = bMax
ones(n,1);
wantedPowerOf10 = 0;

% Example 1
rng(0,‘twister’);
A = (1e-5)rand(n,m);
B = (A.’) * inv(A
(A.’));
C = abs(B).^2;

largestPowerOf10 = max(max(floor(log10©), [], 2));
scalar1 = 10^(largestPowerOf10 - wantedPowerOf10);
Cscaled = C/scalar1;
bscaled = b/scalar1;
uscaled = u/scalar1; % The lower bound is all-zeros and need not be scaled

cvx_begin quiet
variable x(n)
maximize( sum(x) )
subject to
Cscaledx <= bscaled
l <= x <= uscaled
cvx_end
x = x
scalar1

% Example 2
rng(2,‘twister’);
A = (1e-5)rand(n,m);
B = (A.’) * inv(A
(A.’));
C = abs(B).^2;

largestPowerOf10 = max(max(floor(log10©), [], 2));
scalar2 = 10^(largestPowerOf10 - wantedPowerOf10);
Cscaled = C/scalar2;
bscaled = b/scalar2;
uscaled = u/scalar2; % The lower bound is all-zeros and need not be scaled

cvx_begin quiet
variable x(n)
maximize( sum(x) )
subject to
Cscaledx <= bscaled
l <= x <= uscaled
cvx_end
x = x
scalar2
% ---------------------------------------------------

You can change scaling with wantedPowerOf10 (e.g. wantedPowerOf10=1,0,-1, etc.). But to prove my point, you can also change rng(0,‘twister’) to rng(1,‘twister’) in the second line and keep the same scaling factor (wantedPowerOf10=0).

Note that wantedPowerOf10=largestPowerOf10 corresponds to no scaling.

I haven’t looked at or checked what you’ve done. But my first suggestion is for you to determine whether when you get a different solution, you are solving (apart from scaling) the same problem. Specifically, when you change the scaling, are you drawing new (different) random numbers for A, and therefore solving a different problem, i.e., a problem having different input values, not just a difference in scaling? If so, you wouldn’t be the first person on this board who has made such a mistake, and I doubt you’ll be the last.

Hi Mark. I apologize for the ambiguity in my question.

The scaling is set based on the wanted and largest order of magnitude (OM) of the elements in the matrix. This means that all values are normalized with 10^(x-y), where x is the largest OM and y is the wanted OM.

So, while wanted OM is the same for different matrices, the scalar will be different when the largest OM is different.

To answer your question, I believe I am using different scalars for different matrices. Is your suggestion that I set the scalar based on the first matrix (generated from my first Monte Carlo run) and then reuse it for all other matrices (generated in subsequent Monte Carlo runs)?

PS. I have edited the example code in my first post to better illustrate what I mean. You just have to run it and read the optimized output values. You will notice that the chosen scaling works for matrix C in Ex.1, but when we suddently have a different matrix C (imagine a second run of a Monte Carlo simulation) then the impact of scaling becomes evident.

Also, often enough the optimization variables are outputed as negative values and not negligibly small. Since they model transmit power they should non-negative. Any recommendation here? Just zero all negative values?