I was working about polygonal numbers and doing a list of what numbers can be represented as a sum of three 27-gonals. I have done a Matlab code but it is really slow. Can you please help me to improve it?
n=0:100; % number of polygonals
pn=(25*n.^2-23*n)/2; % vector of 27-gonal numbers
s=1;
% the following part generate the list of numbers represented as a sum of three 27- gonals
for n=1:101
for m=1:101
for l=1:101
sumadetres(s)=pn(n)+pn(m)+pn(l);
s=s+1;
end
end
end
k=1;
% some of the numbers are repeted, so the following part eliminated the repeated ones.
n=length(sumadetres);
while k<=n
j=1;
while j<=n
if k~=j
if sumadetres(k)==sumadetres(j)
sumadetres(j)=[];
n=length(sumadetres);
end
end
j=j+1;
end
k=k+1;
end
sumadetres=sort(sumadetres); % organise the numbers
Thanks