function Y = sylv_triangular(UA, LB, E) % solve the equation UA*Y - Y*LB = E, % where UA is upper tr., LB is lower tr. [m, n] = size(E); Y = zeros(m, n); for j = n:-1:1 for i = m:-1:1 num = E(i,j) - UA(i,i+1:end)*Y(i+1:end,j) + Y(i,j+1:end)*LB(j+1:end,j); Y(i,j) = num / (UA(i,i)-LB(j,j)); end end