Try the following code:
n=1;L=1;d=1;q=1;%randomly given
syms alpha
C=0.5*q*sin(alpha)*[L+d];
D=0.5*q*sin(alpha)*[L^2/d];
Q=[-(L+d)/d,L/d;-L/d,(L-d)/d];
n=10;%randomly given
A=sym(zeros(n,1));B=sym(zeros(n,1));%preallocation
for i=1:n
temp=Q*[A(i);B(i)]+[C;D];
A(i+1)=temp(1);
B(i+1)=temp(2);
end
Then display the values to see if they are correctly obtained.