function babydecouple3 global m n m=2;n=3; keyboard return function fc = phicoeffL(xind) global n a=sym('a','real'); b=sym('b','real'); A=[[a b];[1-a,1-b]]; x = i2c(xind)+1; p = 1; for i=1:n-1 p = p * A(x(i+1),x(i)); end fc = p/2; return function fc = phicoeffR(xind) global n a=sym('a','real'); b=sym('b','real'); A=[[a b];[1-a,1-b]]; x = i2c(xind)+1; p0 = [1/2;1/2]; p = 1; for i=0:n-1 Aip = (A^i)*p0; p = p * Aip(x(i+1)); end fc = p; return function lhs = symlhs global n lhs = ''; for xind=1:2^n fc = phicoeffL(xind); fcs = char(fc); xs = i2cs(xind); lhs = [lhs fcs '*x' xs '+']; end lhs = lhs(1:end-1); return function rhs = symrhs global n a=sym('a','real'); b=sym('b','real'); rhs = ''; for xind=1:2^n fc = phicoeffR(xind); fcs = char(fc); xs = i2cs(xind); rhs = [rhs fcs '*x' xs '+']; end rhs = rhs(1:end-1); H = 0; for i=0:n-1 H = H + (a-b)^i; end rhs = ['(' char(H) ')(' rhs ')']; return function i=c2i(c) global m n dims = repmat(m,[1 n]); i = coord2ind(c+1,dims); return function c=i2c(i) global m n dims = repmat(m,[1 n]); c = ind2coord(i,dims)-1; return function cs = i2cs(i) global m n dims = repmat(m,[1 n]); c = ind2coord(i,dims)-1; cs = num2str(c); cs = strrep(cs,' ',''); return