MATLAB: Hello everyone, i tried to understand and implement the sum product algorithm with following examples . can someone help me to implement this in matlab coding

sum product algorithm

H= [1 1 0 1 0 0; 0 1 1 0 1 0;1 0 0 0 1 1;0 0 1 1 0 1]
R=[-0.5 2.5 -4.0 5.0 -3.5 2.5]
A=repmat(R,4,1)
for i=1:4
for j=1:6
mul=1;
for ii=1:4
H(ii,j)==1 && i~=ii
mul=mul*tanh(A(ii,j)/2);
end
X=(1+mul)/(1-mul)
B(ii,j)=log(X)
end
Here, in this example for i=1,j=1 B(1,1)=2.4217 and i&j=2 B(1,2)=-0.4930
To get B(1,1): i have to avoid the element of first row and its first column i.e. -0.5 and and have to multiply 2.5 and 5 only which followed by tanh and natural logarithm.
where;
B(i,j)=ln{1+tanh(L(ii,j)/2)/(1-tanh(L(ii,j)/2)}
and ii=1:4 and i~=ii
i tried to implement this equation in matlab coding but unable to get result. Could you guys help me to find out my error. Thank you all.

Best Answer

The code is wrong in the innermost loop. I believe it should be:
for ii=1:4
if H(ii,j)==1 && i~=ii
mul=mul*tanh(A(ii,j)/2);
end
end
You also have a missing ‘end’ for the outermost loop.
There seems no point in doing the repmat. You could use
tanh(R(j)/2
since A(ii,j) is the same for all ii.