x = [0.3,.5,.6]n = 3lb = zeros(length(x),1)ub = ones(length(x),1)Aeq = [zeros(1,n); ones(1,n)]beq = 1 x = fmincon(@(x) myfunct(x),x,[],[],Aeq,beq,lb,ub)xthis is myfunction belowfunction [z] = myfunct(x) n= length(x)/2;y = 0:1:n;p_y_x = zeros(n,n+1)h_y_x = []for i=1:n for k =1:length(y)p_y_x(i,k) = nchoosek(n,y(k)).*(x(i).^y(k)).*(1-x(i).^(n-y(k))) end index = find(p_y_x(i,:)) p_y_x(i,index) h_y_x = [h_y_x -p_y_x(i,index)*log(p_y_x(i,index))']endsec_term = x(n+1:2*n)*h_y_x'q_y = p_y_x(i,index).*x(n+1:2*n)first_term = q_y*log(q_y)'z = first_term - sec_termend
MATLAB: Row dimension of Aeq is inconsistent with length of beq.
fmincon
Best Answer