Hi, I’m new to CVX Programming. Is my implemetation is correct?


(Samantha Pereis) #1

Hi,
I am new to CVX. I have the following optimization problem, does it support in CVX?

Where p and t are L length known vectors; I need to estimate a and b.
Is following code is correct?
y=ln [p]; and A is a Lx2 matrix
cvx_begin quiet

variable x(2)

minimize( norm(A*x-y)), 2 ));

subject to
y=A*x;

cvx_end

(Mark L. Stone) #2

Equality constraints should be written with == , not = . But it doesn’t make sense to have y == A*x as a constraint in this problem in which you are trying to minimize the norm (squared) of the deviation from that equality being satisfied.

How about

cvx_begin
variables ln_a b
minimize(norm(log(p) - (ln_a - t*b)))
cvx_end

(Samantha Pereis) #3

Thank you, Mark for your response. Is there is any specific reason to use log§ instead of ln§?. Also if I want to satisfied that a>0, a<=1 and b >0, can I use

cvx_begin
variables ln_a b
minimize(norm (log§ - (ln_a - t*b)))
subject to
a>0 && a<=1
b>0
cvx_end


(Mark L. Stone) #4

There is no ln function in MATLAB. But log in MATLAB means natural logarithm.

&& is not allowed to be applied to cvx objects. However, you can use 0 <= a <= 1 . Or you can use two separate constraints.

Also note that > and < are interpreted as >= and <= . if you need strict inequality, you need to use non-strict inequality with a “buffer” larger than solver tolerance. For instance, b >= 1e-5.

You should carefully read CVX Users’ Guide http://cvxr.com/cvx/doc/