Bsxfun + Norm minimization

Hi, Im trying to do this:

minimize( norm( A - bsxfun(@times,Vector1,Vector2) ) )

A is a matrix N by m, N>m
Vector1 is a vector 1 x m
Vector2 is a vector N x 1

so I construct a new matrix by multiplying vectors 1 and 2, and then I want to minimize norm between A and new matrix

How can i do that within cvx? the line above doesn’t work.

You didn’t state that Vector1 and Vector2 were declared in CVX as variables, but I will presume that to be the case. Your objective function is equivalent to minimize(norm(A-Vector2*Vector1)). This is not compliant with the DCP ruleset due to the non-quadratic form product of variables.

As to whether your problem can be formulated so as to comply with the DCP ruleset, that depends on the rest of the problem specification, which you have not provided. The following program segment is valid in CVX, since it avoids disallowed products, but I can not determine whether it will suit your needs.

% A is provided prior to CVX invocation.
cvx_begin
variable Vector1_times_Vector2(n,m)
minimize(norm(A-Vector1_times_Vector2))
cvx_end

Of course, as written above, it is rather uninteresting, and will return the trivially obvious solution Vector1_times_Vector2 = A. You will will have to determine whether your constraints can be adequately handled with this or a similar approach.

Edit based on answer by OP:
In light of Vector2 being input data and Vector1 being the only variable, then as mcg and I both suggested, use * instead of bsxfun, which is not supported in CVX.

% A and Vector2 are provided prior to CVX invocation.
cvx_begin
variable Vector1(1,m)
minimize(norm(A-Vector2*Vector1))
% Insert constraints if you have any
cvx_end

You don’t need bsxfun for that at all. Just do Vector2 * Vector1, which yields an N x m matrix. Of course, Mark’s point is still valid; if both of these are variables, the problem is nonconvex.

Sorry for not specifying what is what:
matrix A - is N by m table with data,
vector2 - is N by 1 vector with data,
vector1 - is 1 by m objective variable

thank you, its silly i didn’t figure it out :slight_smile: it works now!