I'm struggling with this task:
Create a recursive function that takes n as an argument and creates a matrix like this, in this case n = 3:
0 1 2 3 2 1 0
1 1 2 3 2 1 1
2 2 2 3 2 2 2
3 3 3 3 3 3 3
I already came up with this:
function AA = A(n)
if n == 0
AA (1,1) = 0;
else
AA = n*ones(n+1,2*n+1);
AA(1:n, [1:n, n+3:end]) = A(n-1);
end
end
But the output seems to have a weird shift on the RHS:
0 1 2 3 3 2 1
1 1 2 3 3 2 1
2 2 2 3 3 2 2
3 3 3 3 3 3 3
Can someone help?