Origin for each line in src/programming.txt from check-in 5ce5316a33:

5ce5316a33 2021-03-01 jeff@gridfini: %%%%%%%%%%%%%%%%%%%%%
5ce5316a33 2021-03-01 jeff@gridfini: %  PROGRAMMING
5ce5316a33 2021-03-01 jeff@gridfini: %%%%%%%%%%%%%%%%%%%%%
5ce5316a33 2021-03-01 jeff@gridfini: 
5ce5316a33 2021-03-01 jeff@gridfini: % Define number to factorize
5ce5316a33 2021-03-01 jeff@gridfini: x:=42;
5ce5316a33 2021-03-01 jeff@gridfini: 
5ce5316a33 2021-03-01 jeff@gridfini: % Factorize x and write out each individual 
5ce5316a33 2021-03-01 jeff@gridfini: % factor
5ce5316a33 2021-03-01 jeff@gridfini: factors:=factorize(fix(x))$
5ce5316a33 2021-03-01 jeff@gridfini: x:=0$
5ce5316a33 2021-03-01 jeff@gridfini: for i:=1:length(factors) do begin
5ce5316a33 2021-03-01 jeff@gridfini:    q:=part(factors,i);
5ce5316a33 2021-03-01 jeff@gridfini:    for j:=1:part(q,2) do begin
5ce5316a33 2021-03-01 jeff@gridfini:       x:=x+1;
5ce5316a33 2021-03-01 jeff@gridfini:       write "factor ", x, ": ", part(q,1);
5ce5316a33 2021-03-01 jeff@gridfini:    end;
5ce5316a33 2021-03-01 jeff@gridfini: end;
5ce5316a33 2021-03-01 jeff@gridfini: 
5ce5316a33 2021-03-01 jeff@gridfini: % Procedure to calculate Legendre polynomial
5ce5316a33 2021-03-01 jeff@gridfini: % using recursion 
5ce5316a33 2021-03-01 jeff@gridfini: procedure p(n,x);
5ce5316a33 2021-03-01 jeff@gridfini:    if n<0 then rederr "Invalid argument to p(n,x)"
5ce5316a33 2021-03-01 jeff@gridfini:    else if n=0 then 1
5ce5316a33 2021-03-01 jeff@gridfini:    else if n=1 then x
5ce5316a33 2021-03-01 jeff@gridfini:    else ((2*n-1)*x*p(n-1,x)-(n-1)*p(n-2,x))/n$
5ce5316a33 2021-03-01 jeff@gridfini: 
5ce5316a33 2021-03-01 jeff@gridfini: % Enable fancy output
5ce5316a33 2021-03-01 jeff@gridfini: %fancy_output$
5ce5316a33 2021-03-01 jeff@gridfini: 
5ce5316a33 2021-03-01 jeff@gridfini: % Calculate p(2,w)
5ce5316a33 2021-03-01 jeff@gridfini: write "P(2,w) = ", p(2,w);
5ce5316a33 2021-03-01 jeff@gridfini: 
5ce5316a33 2021-03-01 jeff@gridfini: % Incidentally, p(n,x) can be calculated more
5ce5316a33 2021-03-01 jeff@gridfini: % efficiently as follows
5ce5316a33 2021-03-01 jeff@gridfini: procedure p(n,x);
5ce5316a33 2021-03-01 jeff@gridfini:    sub(y=0,df(1/(y^2-2*x*y+1)^(1/2),y,n))/(for i:=1:n product i)$
5ce5316a33 2021-03-01 jeff@gridfini: 
5ce5316a33 2021-03-01 jeff@gridfini: write "P(3,w) = ", p(3,w);
5ce5316a33 2021-03-01 jeff@gridfini: 
5ce5316a33 2021-03-01 jeff@gridfini: end;

olli-scripts
English Homepage | German Homepage | DL2MIE | GitHub Mirror | SourceHut Mirror | NotABug Mirror | Chisel Mirror | Chisel RSS ]