[Scilab-users] Visualising Collatz sequences
Stéphane Mottelet
stephane.mottelet at utc.fr
Thu Apr 14 09:46:01 CEST 2022
Hi again,
Here is a small code doing the graphic job:
function X=anglePath(r, th)
cumth = cumsum(th);
X = cumsum([0 r.*cos(cumth);0 r.*sin(cumth)], 2);
end
function N=collatz(n)
N = n;
while n<>1
if modulo(n,2) == 0
n = n/2;
else
n = 3*n+1;
end
N = [n N];
end
end
a=0.08;
e=1.2;
clf
gcf().color_map=graycolormap(128);
for i=1:100
r=collatz(ceil(rand()*2000000000));
X=anglePath(r./(1+r.^1.2),a*%pi*(0.35-modulo(r,2)));
plot(0.01+X(1,:),-0.01+X(2,:));
end collatz
--
Stéphane Mottelet
Ingénieur de recherche
EA 4297 Transformations Intégrées de la Matière Renouvelable
Département Génie des Procédés Industriels
Sorbonne Universités - Université de Technologie de Compiègne
CS 60319, 60203 Compiègne cedex
Tel : +33(0)344234688
http://www.utc.fr/~mottelet
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.scilab.org/pipermail/users/attachments/20220414/7a9fd0e4/attachment.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Figure%20n%C2%B00.jpg
Type: image/jpeg
Size: 43772 bytes
Desc: not available
URL: <https://lists.scilab.org/pipermail/users/attachments/20220414/7a9fd0e4/attachment.jpg>
More information about the users
mailing list