function P = transfer_operators(mg)

P = {};

for k=(length(mg)-1):-1:1
    n = length(mg{k});
    m = length(mg{k+1});
    nnz = n*3-2;
    ii = zeros(1,nnz);
    jj = zeros(1,nnz);
    ss = zeros(1,nnz);
    
    nz = 1;
    ii(1:2) = [1 2];
    jj(1:2) = [1 1];
    ss(1:2) = [1 .5];
    nz = nz + 2;
    for r=2:n-1
        ii(nz:nz+2) = [2*r-2 2*r-1 2*r];
        jj(nz:nz+2) = [r r r];
        ss(nz:nz+2) = [.5 1 .5];
        nz = nz+3;
    end
    ii(nz:nz+1) = [2*n-2 2*n-1];
    jj(nz:nz+1) = [n n];
    ss(nz:nz+1) = [.5 1];

    P{k} = sparse(ii,jj,ss,m,n);
end




