function index = n_comp3index (N) if N < 1 then N = 1 end N = floor(N) i = 1:ceil(N/3) i = i^2 index = [] for j = 1:length(i) for k = 1:length(i) index = [index i+ i(j).*ones(i)+i(k).*ones(i)] end end index = unique(index) index = gsort([index], "g", "i") index = index(1:N) endfunction function l = n_comp3_n (i) a1 = 0 a2 = 0 a3 = 0 l=0 while (i > (a1^2 +a2^2+a3^2)) while (i > (a1^2 + a2^2)) while (i > (a1^2)) if ((i > a1^2+a2^2+a3^2) & (i>= (a1+1)^2+(a2+1)^2+(a3+1)^2)) then if ((a1==a2) | (a2==a3) | (a1==a3)) then if ((a1==a2) & (a2==a3)) then l=l+1 else l=l+3 end else l=l+6 end end a1=a1+1 end a2=a2+1 a1=a2 end a3=a3+1 a2=a3 a1=a2 end endfunction function l = n_edge3_n (i) a1 = 0 a2 = 0 a3 = 0 l=0 while (i > (a1^2 +a2^2+a3^2)) while (i > (a1^2 + a2^2)) while (i > (a1^2)) if ((i > a1^2+a2^2+a3^2) & (i< (a1+1)^2+(a2+1)^2+(a3+1)^2)) then if ((a1==a2) | (a2==a3) | (a1==a3)) then if ((a1==a2) & (a2==a3)) then l=l+1 else l=l+3 end else l=l+6 end end a1=a1+1 end a2=a2+1 a1=a2 end a3=a3+1 a2=a3 a1=a2 end endfunction function a =n_comp3 (N) if N <1 then N =1 end N = floor(N) a= [] index = n_comp3index(N) for i = index a = [a n_comp3_n(i)] end endfunction