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.
variable Vector1_times_Vector2(n,m)

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.
variable Vector1(1,m)
% Insert constraints if you have any

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!