function td = comvkomb(K,m,n) % try to express K as a conv. comb of other elements % of [-1,1]^(m^n) iip = find(K>0); e1 = min(K(iip)); e2 = min(1-K(iip)); e = min(e1,e2); i1 = iip(1); i2 = iip(2); K0 = K; v0 = Psi(K0,m,n); % WANT: % (i) Psi(K1), Psi(K2) <= v0 % (ii) K0 = (K1+K2)/2 d1=e; d2=e; while 1 K1 = K0; K1(i1) = K1(i1) + d1; %x = binsearch(K1,i2,v0,m,n); %d = K1(i2) - x; K1(i2) = K1(i2) - d2; %if d > e % e = e/2; %else % break %end %end K2 = K0; K2(i1) = K2(i1) - d1; K2(i2) = K2(i2) + d2; % (ii) is ensured automatically v1 = Psi(K1,m,n); v2 = Psi(K2,m,n); g = ((v1<=v0) & (v2<=v0)); if g break else if (v1 > v0) d1 = d1/2; end if (v2 > v0) d2 = d2/2; end end end totdif((K1+K2)/2,K0); return function x = binsearch(K,i,v,m,n) lowx = 0; higx = 1; tol = 1e-8; while higx - lowx > tol x = (lowx + higx)/2; K(i) = x; vx = Psi(K,m,n); if vx < v % too small; make x bigger lowx = x; else % too bix; make x smaller higx = x; end end return