How to define this recursive formula in MatLAB I have a matrix-valued function defined as R which depends on n and I want to define the following algorithm in MatLAB:
$A_{0}=I$ , $B_{0}=0$ , $A_{1}=I$ ,$B_{1}=I$
for $j=1:2m$
$A_{j}= R_{j}A_{j-1}+A_{j-2}$;$B_{j}= R_{j}B_{j-1}+B_{j-2};$
end
$K_{m}=A_{2m}B_{2m}$, I have the following code in MatLAB, it does not work because of some mismatch assignments. I think I am making some mistakes in the array assignments. I'd appreciate any hints or comments. Thanks

Here is an example with cell arrays.

