Recursive definition of n mod k, Scilab, Matlab

x=10;  
T=zeros(x,x);  

for n=1:x;
  for k=n+1:x;
    T(n,k)=n;
    end
end

for n=1:x;  
T(n,1)=0;  
end 
T  
for n=2:x;  
for k=2:n;  
s = 0;  
for i=1:k-1;  
//recursive definition of divisibility without using the mod function, table A051731 in the oeis.  
s=s+T(n-i,k-1)-T(n-i,k);  
end 
T(n,k)=s+k-1;  
end 
end 
T  
//Mats Granvik email: mats.granvik(at)abo.fi 
Advertisements
This entry was posted in Uncategorized. Bookmark the permalink.