I have no idea what you're trying to do. First of all, Z(1) will depend on Z(1) which hasn't been defined yet so that will bomb. Next, i-j will equal zero when both i and j are 1, so that will bomb also. Beyond that I have no idea whatsoever what you're trying to do. And what is S?