Zurück zum Inhaltsverzeichnis

Kapitel 9

Folgen, Mengen und Listen (Einführung)

> restart:

> min(1, sqrt(2), sqrt(2)/2);

1/2*sqrt(2)

> f:=expand((x-2)^3 * (x-3) * (x-1));

f := x^5-10*x^4+39*x^3-74*x^2+68*x-24

> roots(f);

[[1, 1], [2, 3], [3, 1]]

> solve(x^4-10*x^3+35*x^2-50*x+24,x);

1, 2, 3, 4

> solve( {x^2+y^2=13, x^2-y^2=5},{x,y});

{y = 2, x = 3}, {x = -3, y = 2}, {y = -2, x = 3}, {...

> plot( {sin(x), sin(3*x)/3, sin(5*x)/5}, x=0..Pi);

[Maple Plot]

Folgen

> sq :=a,b,c;

sq := a, b, c

> sq := seq(2^n-2*n, n=0..3);

sq := 1, 0, 0, 2

> seq(i^2,i=1.5..3);

2.25, 6.25

> seq(i^2, i=[1.5, 2, 2.5, 3] );

2.25, 4, 6.25, 9

> seq(i^2, i=seq(j*0.5, j=3..6));

2.25, 4.00, 6.25, 9.00

> seq(seq(i,i=1..n),n=1..5);

1, 1, 2, 1, 2, 3, 1, 2, 3, 4, 1, 2, 3, 4, 5

> sq1:=sq,8;

sq1 := 1, 0, 0, 2, 8

> sq[4];

2

> sq[2..4];

0, 0, 2

> sq1[-2..-1];

2, 8

> sq[2]:=5;

Error, cannot assign to an expression sequence

> sq1:=op( subsop(2=5,[sq1]) );

sq1 := 1, 5, 0, 2, 8

> sq1:=op( subsop(4=NULL,[sq1]) );

sq1 := 1, 5, 0, 8

Listen

> lst := [1,2,3];

lst := [1, 2, 3]

> lst := [seq(2^n-2*n,n=0..3)];

lst := [1, 0, 0, 2]

> lst[2];

0

> st:= subsop(2=3,lst);

st := [1, 3, 0, 2]

> lst:= [a,b,op(lst),c,d,x,x^2,x^3];

lst := [a, b, 1, 0, 0, 2, c, d, x, x^2, x^3]

> sort(lst);

[0, 0, 1, 2, c, x, a, d, x^2, x^3, b]

> sort( [e,E,Z,b,a]);

[E, Z, a, b, e]

> sort( [e,E,Z,b,a,x,x^2,x^3],lexorder);

Error, invalid arguments to sort

Mengen

> st:={0,1,2};

st := {0, 1, 2}

> {1,2,3} union {3,4,5};

{1, 2, 3, 4, 5}

> {1,2,3,4,5} intersect {4,5,6};

{4, 5}

> {1,2,3,4} minus {1,2};

{3, 4}

Geschachtelte Listen und Mengen

> lst:=[{1,2,3},[a,b,c,d,e],x];

lst := [{1, 2, 3}, [a, b, c, d, e], x]

> lst[2];

[a, b, c, d, e]

> lst[2][3];

c

> lst[2][2..4];

[b, c, d]

> lst[1..2][1];

{1, 2, 3}

> lst:=subsop( 2=subsop(3=x, lst[2]),lst );

lst := [{1, 2, 3}, [a, b, x, d, e], x]

member und select

> member( 2, [1,2,3]);

true

> member( x^3, [x, x^2, x^3], 'pos'):

> pos;

3

> data:=seq(rand(1..20)(),i=1..10);

data := 7, 10, 14, 2, 15, 7, 14, 3, 12, 14

> select(isprime, [data]);

[7, 2, 7, 3]

> select(type,[data],odd);

[7, 15, 7, 3]

> select(has,[data],{12,13,14});

[14, 14, 12, 14]

map und zip

> [1,2,3] + [4,5,6];

[5, 7, 9]

> [1,2,3] - 2*[4,5,6];

[-7, -8, -9]

> 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);

[1, sqrt(2), sqrt(3)]

> map( [sin,cos],1);

[sin(1), cos(1)]

> map( [sin,cos], [1,2]);

[[sin(1), cos(1)], [sin(2), cos(2)]]

> map( arctan, x,y);

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] );

[arctan(x1,y1), arctan(x2,y2)]

> zip( irem, [12,15,11], [3,4,5]);

[0, 3, 1]

> zip( (x,y)->[x,y], [x1,x2,x3], [y1,y2,y3] );

[[x1, y1], [x2, y2], [x3, y3]]

>

Zurück zum Inhaltsverzeichnis