I need to compute this equation with MATLAB:
where Sn can be both matrices or scalar and I tried to do it with 
S_A = S_3*S_5*((ones-(S_1*S_5)).^(-1))*S_2+S_4
The problem is it doesn't give me the right result and the problem it seems to be with the difference 
 but I cannot figure why is giving me wrong results.
The result is supposed to be this one
but the MATLAB result is
I don't understand why the two results are not the same. The only way that I figured is through this
diff = ones-(S_1*S_5);
if S_1*S_5 == zeros         %Perchè senza non funziona?
    diff = ones;
else 
    diff = (ones-(S_1*S_5)).^(-1)
end
S_A = S_3*S_5*diff*S_2+S_4;
But I don't think it's a smart solution. Anyone knows why I'm not getting the correct results?


