function x = babyaux(x) global saf raf Ainf Binf x = fmincon(@radrat,x,Ainf,Binf,[],[],0*x+saf,0*x+raf); return function y = radrat(x) global m n P U a b lhs = P'*x; rhs = U'*x; tha = abs(a-b); Hn = sum(tha.^[0:n-1]); %rhs = rhs*(1+abs(a-b)); rhs = rhs*Hn; %hold on %plot(lhs,rhs,'.b'); %drawnow %[L1 R1] = babycheck(x) %if abs(L1-lhs)+abs(R1-rhs) > 1e-9 % keyboard %end r = lhs/rhs; y = -r; global maxr if r > maxr maxr = r; end return function [lhs, rhs] = babycheck(x) global m n a b lhs = 1/2 * ( a*x(c2i([0 0])) + (1-a)*x(c2i([0 1])) + b*x(c2i([1 0])) + (1-b)*x(c2i([1 1])) ); rhs = 1/4 * (1+abs(a-b)) * ((a+b)*(x(c2i([0 0]))+x(c2i([1 0]))) + (2-a-b)*(x(c2i([0 1]))+x(c2i([1 1])))); return function i=c2i(c) global m n dims = repmat(m,[1 n]); i = coord2ind(c+1,dims); return