How to sovle this QP problem in cvx?

u is the variable vector
objective fucntion is:

min ||u.ker - idealKer||f^2 + lamda ||u||2^2

subject to:

 u1,u2,u3>=0
 u1+u2+u3=1;

matlab code is:

clc
clear
viewNum = 3;
lamda = 100;
u = 1/viewNum*ones(1,viewNum);
ker = cell(1,viewNum);
ker{1} = rand(6,6);
ker{2} = rand(6,6);
ker{3} = rand(6,6);
idealKer = [1 1 0 0 0 0;
            1 1 0 0 0 0;
            0 0 1 1 0 0;
            0 0 1 1 0 0;
            0 0 0 0 1 1;
            0 0 0 0 1 1];
cvx_begin
    variable u(1,viewNum)
    minimize( square_pos(norm(u.*ker - idealKer,'fro')) + lamda*square_pos(norm( u ,2)))
    subject to
        u >= 0
        u*ones(viewNum,1) == 1
cvx_end

run this code, matlab show me the error:

Undefined function ‘real’ for input arguments of type ‘cell’.

how to solve this promble?

could anybody help me?

Forget CVX for the moment. Just assign every “variable” (vector or matrix) some value in MATLAB. Then whatever expression you formulate, has to evaluate without error in MATLAB, including being conformal.Your u.*ker is not conformal. When you get that figured out, then try to implement it in CVX.

clc
clear
viewNum = 3;
lamda = 100;
u = 1/viewNum*ones(1,viewNum);
ker = cell(1,viewNum);
ker{1} = rand(6,6);
ker{2} = rand(6,6);
ker{3} = rand(6,6);
idealKer = [1 1 0 0 0 0; 1 1 0 0 0 0; 0 0 1 1 0 0; 0 0 1 1 0 0; 0 0 0 0 1 1; 0 0 0 0 1 1];
cvx_begin
    variable u(1,viewNum)
    minimize( square_pos(norm(u(1).*ker{1}+u(2).*ker{2}+u(3).*ker{3} - idealKer,'fro')) +  lamda*square_pos(norm( u ,2)))
    subject to
        u >= 0
        u*ones(viewNum,1) == 1
cvx_end

I do not known, whether it is right?

Well, it executes and produces a solution. As to whether your formulation is correct, it’s your model, so you should know better than people reading your post. Note that your statement u = 1/viewNum*ones(1,viewNum); is extraneous, since CVX does not use user-supplied starting values.

but I try “u = 1/viewNumones(1,viewNum);" and "u = 100/viewNumones(1,viewNum);” ,get different result.This show me that CVX is sensitive the starting values. This is different to your comment. Which is right?

I suspect you generated new random numbers, i.e., re-executed ker{1} = rand(6,6); etc., so you were solving different problem instantiations. If you re-run with the same random numbers and the same solver, and with or without your u assignment, you should get the same solution.

Mark is indeed correct: the initial value of u is completely ignored. There must be another explanation for the differences you are seeing.