Kapitel 9
Folgen, Mengen und Listen (Einführung)
> restart:
> min(1, sqrt(2), sqrt(2)/2);
> f:=expand((x-2)^3 * (x-3) * (x-1));
> roots(f);
> solve(x^4-10*x^3+35*x^2-50*x+24,x);
> solve( {x^2+y^2=13, x^2-y^2=5},{x,y});
> plot( {sin(x), sin(3*x)/3, sin(5*x)/5}, x=0..Pi);
Folgen
> sq :=a,b,c;
>
sq := seq(2^n-2*n, n=0..3);
> seq(i^2,i=1.5..3);
> seq(i^2, i=[1.5, 2, 2.5, 3] );
> seq(i^2, i=seq(j*0.5, j=3..6));
> seq(seq(i,i=1..n),n=1..5);
> sq1:=sq,8;
> sq[4];
> sq[2..4];
> sq1[-2..-1];
> sq[2]:=5;
Error, cannot assign to an expression sequence
> sq1:=op( subsop(2=5,[sq1]) );
> sq1:=op( subsop(4=NULL,[sq1]) );
Listen
> lst := [1,2,3];
> lst := [seq(2^n-2*n,n=0..3)];
> lst[2];
> st:= subsop(2=3,lst);
> lst:= [a,b,op(lst),c,d,x,x^2,x^3];
>
sort(lst);
> sort( [e,E,Z,b,a]);
> sort( [e,E,Z,b,a,x,x^2,x^3],lexorder);
Error, invalid arguments to sort
Mengen
> st:={0,1,2};
> {1,2,3} union {3,4,5};
> {1,2,3,4,5} intersect {4,5,6};
> {1,2,3,4} minus {1,2};
Geschachtelte Listen und Mengen
> lst:=[{1,2,3},[a,b,c,d,e],x];
> lst[2];
> lst[2][3];
> lst[2][2..4];
> lst[1..2][1];
> lst:=subsop( 2=subsop(3=x, lst[2]),lst );
member und select
> member( 2, [1,2,3]);
> member( x^3, [x, x^2, x^3], 'pos'):
> pos;
> data:=seq(rand(1..20)(),i=1..10);
> select(isprime, [data]);
> select(type,[data],odd);
> select(has,[data],{12,13,14});
map und zip
> [1,2,3] + [4,5,6];
> [1,2,3] - 2*[4,5,6];
> lst:=[1,2,3]: sqrt(lst);
Error, sqrt expects its 1st argument, x, to be of type algebraic, but received [1, 2, 3]
> map(sqrt, lst);
> map( [sin,cos],1);
> map( [sin,cos], [1,2]);
> map( arctan, x,y);
> map(sqrt, [1,2,[3,4]]);
Error, sqrt expects its 1st argument, x, to be of type algebraic, but received [3, 4]
> map( arctan, [x1,x2], [y1,y2]);
Error, arctan expects its 2nd argument, x, to be of type algebraic, but received [y1, y2]
> zip(arctan, [x1,x2], [y1,y2] );
> zip( irem, [12,15,11], [3,4,5]);
> zip( (x,y)->[x,y], [x1,x2,x3], [y1,y2,y3] );
>