Suppose I have vectors z1 z2 z3 z4 and b and matrices D1 D2 D3 D4.
I want to construct:
b1 = D2*z2 + D3*z3 +D4*z4 -b
b2 = D1*z1 + D3*z3 +D4*z4 -b
b3 = D1*z1 + D2*z2 +D4*z4 -b
b4 = D1*z1 + D2*z2 +D3*z3 -b
I planned to store my z vectors and D matrices in cells and extract them to create b by a for loop. e.g.
for i = 1:3
b(i) = D{i+1}*z{i+1} + D{i}*z{i};
end
Of course it certainly fails because it involves D{i}*z{i} at each i step. Can you please help me to accomplish my task?