Search code examples
matlabminimization

MATLAB code for Minimization of vectors


Question: What type of optimization function in MatLab should I use to solve the following minimization matrix problem?

I am trying to find the row vector V such that [[ (f – transpose(V) * R) ]] is minimized subject to:

transpose(V)*B = 0.

++++Variables:

  • f is a scalar which is known.
  • R is (8x1) row vector which is known.
  • B is (8x1) row vector which is known.
  • V is (8x1) row vector which is unknown and I want to find that.

+++++More Conditions:

  • The value of the eight found entries in row vector V (8x1) should be between 0 and 1.

  • The sum of the value of all eight entries of row vector V (8x1) should be unity (one).

Thanks, Matt


Solution

  • you should use fmincon:

    % random inputs f, R, B
    f = rand;
    R = 2*rand(8,1) - 1;
    B = 2*rand(8,1) - 1;
    % minimization term
    fun = @(V) abs(f - V'*R);
    % constrains: transpose(V)*B = 0 and sum(V) = 1
    Aeq = [B';ones(1,8)];
    beq = [0;1];
    % lower (0) and upper (1) bounds
    lb = zeros(8,1);
    ub = ones(8,1);
    % initial guess
    V0 = rand(8,1);V0 = V0/sum(V0);
    % constrained minimization
    V = fmincon(fun,V0,[],[],Aeq,beq,lb,ub);
    % check result
    sum(V) % should be 1
    V'*B % sould be 0
    [min(V) max(V)] % should be between 0 to 1