Matlab: Maximization of sum of logarithms

501 Views Asked by At

I have the following vectors/matrices:

a --> nx1 
b --> nx1
C --> nxn

Given I know a and C, I want to maximize the following in Matlab by varying vector b:

S = a(1)*log(sum(b.*C(:,1),1))+...+a(n)*log(sum(b.*C(:,n),1))

So each element of the sum S to be maximized is formed by:

  1. i'th element of vector a multiplied by (2)
  2. natural logarithm of (3)
  3. sum of elements obtained in (4)
  4. element-by-element multiplication of the elements of vector b by the elements of the i'th column of matrix C

The constraints to the problem are that each element of b must be >=0 and <=1, and that they must sum to 1.

I assume I would have to use the fmincon function and minimze -S but not sure how to setup function S.

1

There are 1 best solutions below

0
On

since you know C and a, this is almost simple problem. just define a function within the folder of main problem with for example this name "min_sum_log.m".

function S = min_sum_log(b)

S = sum(repmat(b,1,n).*C)*a;

end

in the above code you must define a and C in function body which i leave it to you. also you can define them as global and define them somewhere else. then in the main program you need to call fmincon with the defined function handle:(something like this)

[b_opt,value] = fmincon(@min_sum_log,b_0,[],[],[],[],zeros(n,1),ones(n,1));

in which b_0 is an initial point in vector space of solutions of b. (because this problem is convex and simple, also you can consider using CVX)