Re: [Scilab-users] Visualising Collatz sequences

2022-04-14 Thread Lester Anderson
Hi Stephane,

Many thanks for the code pointers - graphics look fab!

Cheers
Lester

On Thu, 14 Apr 2022 at 15:29, Stéphane Mottelet 
wrote:

> You can also enjoy the 3d version:
>
> function X=anglePath3(r, th, ph)
> cumth = cumsum(th);
> cumph = cumsum(ph);
> X = cumsum([0 r.*sin(cumph)
> 0 r.*sin(cumth).*cos(cumph)
> 0 r.*cos(cumth).*cos(cumph)], 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];
> endend
> a=0.1;e=1.3;
> clfNCOL=512;gcf().color_map=parulacolormap(NCOL);drawlaterfor i=1:200
> r=collatz(grand(1,1,'uin',1,100));
> m1=modulo(r,4);
> m2=m1;
> m1(m1>1)=0;
> m2(m2<=1)=0;
> 
> X=anglePath3(r./(1+r.^e),a*%pi*(0.352-modulo(m1,2)),a*%pi*(0.352-modulo(m2,2)));
> x=rand(3,1)/8;
> param3d(x(1)+X(1,:),x(2)+X(2,:),x(3)+2*X(3,:))
> gce().foreground=min(NCOL,length(r))endisoview ondrawnow
>
>
> Le 14/04/2022 à 09:46, Stéphane Mottelet a écrit :
>
> 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];
> endend
> a=0.08;e=1.2;
> clfgcf().color_map=graycolormap(128);for i=1:100
> r=collatz(ceil(rand()*20));
> X=anglePath(r./(1+r.^1.2),a*%pi*(0.35-modulo(r,2)));
> plot(0.01+X(1,:),-0.01+X(2,:));end
>
>
>
> --
> 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)344234688http://www.utc.fr/~mottelet 
> 
>
>
> ___
> users mailing 
> listusers@lists.scilab.orghttps://antispam.utc.fr/proxy/v3?i=Zk92VEFKaGQ4Ums4cnZEUWMTpfHaXFQGRw1_CnOoOH0=bHA1dGV3NWJQVUloaWNFUYH-0fCrCfKNwGzaHK3mGAF34Dbd5QpdXfVRjdiNrR7K=SlhDbE9uS2laS2JaZFpNWvypxfeihkZF7xphlFhpLfOsI1HEbZ2YCuIwSI8iQL53=http%3A//lists.scilab.org/mailman/listinfo/users=XRKU
>
> --
> 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)344234688http://www.utc.fr/~mottelet
>
> ___
> users mailing list
> users@lists.scilab.org
> http://lists.scilab.org/mailman/listinfo/users
>
___
users mailing list
users@lists.scilab.org
http://lists.scilab.org/mailman/listinfo/users


Re: [Scilab-users] Visualising Collatz sequences

2022-04-14 Thread Stéphane Mottelet

You can also enjoy the 3d version:

function  X=anglePath3(r, th, ph)
cumth  =  cumsum(th);
cumph  =  cumsum(ph);
X  =  cumsum([0  r.*sin(cumph)
0  r.*sin(cumth).*cos(cumph)
0  r.*cos(cumth).*cos(cumph)],  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.1;
e=1.3;

clf
NCOL=512;
gcf().color_map=parulacolormap(NCOL);
drawlater
for  i=1:200
r=collatz(grand(1,1,'uin',1,100));
m1=modulo(r,4);
m2=m1;
m1(m1>1)=0;
m2(m2<=1)=0;

X=anglePath3(r./(1+r.^e),a*%pi*(0.352-modulo(m1,2)),a*%pi*(0.352-modulo(m2,2)));
x=rand(3,1)/8;
param3d(x(1)+X(1,:),x(2)+X(2,:),x(3)+2*X(3,:))
gce().foreground=min(NCOL,length(r))
end
isoview  on
drawnow


Le 14/04/2022 à 09:46, Stéphane Mottelet a écrit :


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()*20));
 X=anglePath(r./(1+r.^1.2),a*%pi*(0.35-modulo(r,2)));
 plot(0.01+X(1,:),-0.01+X(2,:));
end
--
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

___
users mailing list
users@lists.scilab.org
https://antispam.utc.fr/proxy/v3?i=Zk92VEFKaGQ4Ums4cnZEUWMTpfHaXFQGRw1_CnOoOH0=bHA1dGV3NWJQVUloaWNFUYH-0fCrCfKNwGzaHK3mGAF34Dbd5QpdXfVRjdiNrR7K=SlhDbE9uS2laS2JaZFpNWvypxfeihkZF7xphlFhpLfOsI1HEbZ2YCuIwSI8iQL53=http%3A//lists.scilab.org/mailman/listinfo/users=XRKU


--
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
___
users mailing list
users@lists.scilab.org
http://lists.scilab.org/mailman/listinfo/users


Re: [Scilab-users] Combinatorics

2022-04-14 Thread Stéphane Mottelet

Hi,

Le 14/04/2022 à 13:12, Claus Futtrup a écrit :


Dear Scilabers

I hope you can help me out. My combinatorics is a bit rusty.

So, the spouse has purchased a lock and I wondered how many 
combinations are available?


The lock has 10 push buttons, they are numbered 1-2-3-4-5-6-7-8-9-0.

From a programming point of view, any of the numbers can be set on or 
off, meaning there are 2^10 = 1024 combinations, as far as I can see.


I wonder how they are distributed, and how many of the numbers I 
should activate in the lock to maximize the number of combinations?


The number of different subsets of k distincts elements of a set 
composed of n elements is the binomial coefficient (n,k). When n is 
even, it is maximized for k=n/2. Here


-->  nchoosek(10, 5)
 ans  =

   252.

S.


Let's see, we have:

None (none of the buttons are activated), there's exactly 1 
combination for this situation. The lock is delivered from the 
manufacturer in this state.


All (all of the buttons are activated), there's exactly 1 combination 
for this situation as well (no variability).


One button pushed. There's obviously 10 possible combinations (push 
any one of the 10 buttons).


Two buttons pushed. There's 10 * 9 / 2 = 45 combinations. Each button 
can only be pushed once, so once you've selected the first button, 
there's only 9 left, but also we divide by two because the combination 
are doubled, I mean for example the combination 1-2 = 2-1 ... the lock 
doesn't know the difference. If you spread out the possibilities in a 
2D plane, it's like ignoring the diagonal (like pushing the same 
button twice) and also we either ignore the upper or lower triangle. 
Makes sense?


Here starts my trouble. Three buttons pushed. Instead of looking at a 
2D plane, I guess you spread out in 3D. The diagonal line is more than 
that - we have several planes where two of the three numbers are the 
same (and which are not allowed).


To help myself out, I've tried to write all combinations where one of 
the push buttons is number 1. We select all combinations with the 
second button being either 2-3-4 and so on, and how many combinations 
do we then have for the third option? See table below:


1-2-x   8
1-3-x   7
1-4-x   6
1-5-x   5
1-6-x   4
1-7-x   3
1-8-x   2
1-9-0   1

36

We can then do the same for the first button = number 2, and we get : 
7 + 6 + 5 + 4 + 3 + 2 + 1 = 28 combinations and so on. We get:


1-x-y   36
2-x-y   28
3-x-y   21
4-x-y   15
5-x-y   10
6-x-y   6
7-x-y   3
8-9-0   1

120

OK, so that was with three buttons pushed. It's always good to know 
the answer (if it's correct :-/ I hope it is), but it's a tedious 
process and I was wondering if you could point me to an easy 
calculation instead? ... Ideally something that expands to 4 and 5 
buttons.


I can 'invent' a calculation, which could be : =10*9*8/(3*2*1) = 120 
... if this indeed shows the internal workings, I'd like to know why. 
Sorry my combinatorics is so bad ... I haven't played in this field 
for a while.


Best regards,

Claus


___
users mailing list
users@lists.scilab.org
http://lists.scilab.org/mailman/listinfo/users


--
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
___
users mailing list
users@lists.scilab.org
http://lists.scilab.org/mailman/listinfo/users


[Scilab-users] Combinatorics

2022-04-14 Thread Claus Futtrup

Dear Scilabers

I hope you can help me out. My combinatorics is a bit rusty.

So, the spouse has purchased a lock and I wondered how many combinations 
are available?


The lock has 10 push buttons, they are numbered 1-2-3-4-5-6-7-8-9-0.

From a programming point of view, any of the numbers can be set on or 
off, meaning there are 2^10 = 1024 combinations, as far as I can see.


I wonder how they are distributed, and how many of the numbers I should 
activate in the lock to maximize the number of combinations?


Let's see, we have:

None (none of the buttons are activated), there's exactly 1 combination 
for this situation. The lock is delivered from the manufacturer in this 
state.


All (all of the buttons are activated), there's exactly 1 combination 
for this situation as well (no variability).


One button pushed. There's obviously 10 possible combinations (push any 
one of the 10 buttons).


Two buttons pushed. There's 10 * 9 / 2 = 45 combinations. Each button 
can only be pushed once, so once you've selected the first button, 
there's only 9 left, but also we divide by two because the combination 
are doubled, I mean for example the combination 1-2 = 2-1 ... the lock 
doesn't know the difference. If you spread out the possibilities in a 2D 
plane, it's like ignoring the diagonal (like pushing the same button 
twice) and also we either ignore the upper or lower triangle. Makes sense?


Here starts my trouble. Three buttons pushed. Instead of looking at a 2D 
plane, I guess you spread out in 3D. The diagonal line is more than that 
- we have several planes where two of the three numbers are the same 
(and which are not allowed).


To help myself out, I've tried to write all combinations where one of 
the push buttons is number 1. We select all combinations with the second 
button being either 2-3-4 and so on, and how many combinations do we 
then have for the third option? See table below:


1-2-x   8
1-3-x   7
1-4-x   6
1-5-x   5
1-6-x   4
1-7-x   3
1-8-x   2
1-9-0   1

36

We can then do the same for the first button = number 2, and we get : 7 
+ 6 + 5 + 4 + 3 + 2 + 1 = 28 combinations and so on. We get:


1-x-y   36
2-x-y   28
3-x-y   21
4-x-y   15
5-x-y   10
6-x-y   6
7-x-y   3
8-9-0   1

120

OK, so that was with three buttons pushed. It's always good to know the 
answer (if it's correct :-/ I hope it is), but it's a tedious process 
and I was wondering if you could point me to an easy calculation 
instead? ... Ideally something that expands to 4 and 5 buttons.


I can 'invent' a calculation, which could be : =10*9*8/(3*2*1) = 120 ... 
if this indeed shows the internal workings, I'd like to know why. Sorry 
my combinatorics is so bad ... I haven't played in this field for a while.


Best regards,

Claus
___
users mailing list
users@lists.scilab.org
http://lists.scilab.org/mailman/listinfo/users