Zurück zum Inhaltsverzeichnis

Kapitel 11

> restart;

Terme

> f:=x^2-3*x;

f := x^2-3*x

> f1:=2*diff(f,x);

f1 := 4*x-6

> eval(f1,x=3);

6

Funktionen

> restart;

> f:=x->x^2-3*x;

f := proc (x) options operator, arrow; x^2-3*x end ...

> f(x), f(sin(y)), f(25.77);

x^2-3*x, sin(y)^2-3*sin(y), 586.7829

> diff(f(x),x);D(f);

2*x-3

proc (x) options operator, arrow; 2*x-3 end proc

> g:=(x,y,z)->(x^y)^z;

g := proc (x, y, z) options operator, arrow; (x^y)^...

> g(a,b,c), g(2,3,4);

(a^b)^c, 4096

> f:=x->x^2; g:=y->y^3;

f := proc (x) options operator, arrow; x^2 end proc...

g := proc (y) options operator, arrow; y^3 end proc...

> (f+2*g)(z), (f*g)(z), (f@g)(z);

z^2+2*z^3, z^5, z^6

> f:=x->(x,1+1/x);

f := proc (x) options operator, arrow; x, 1+1/x end...

> g:=(x,y)->(x^2/y,y^2/x);

g := proc (x, y) options operator, arrow; x^2/y, y^...

> f(3), (g@f)(3);

3, 4/3, 27/4, 16/27

> wertetab:=f->[seq([i,f(i)],i=-3..3)];

wertetab := proc (f) options operator, arrow; [seq(...

> wertetab(x->x^2);

[[-3, 9], [-2, 4], [-1, 1], [0, 0], [1, 1], [2, 4],...

>

>

unapply

> f:=x->1/(1+x^2): f1:=x->diff(f(x),x);

f1 := proc (x) options operator, arrow; diff(f(x),x...

> f1(1);

Error, (in f1) wrong number (or type) of parameters in function diff

> f1:=unapply( diff(f(x),x), x);f2:=D(f);

f1 := proc (x) options operator, arrow; -2*x/((1+x^...

f2 := proc (x) options operator, arrow; -2*x/((1+x^...

> f1(1);

-1/2

> unapply(a*x^2+b*y^2+c*z^2,x,y,z);

proc (x, y, z) options operator, arrow; a*x^2+b*y^2...

> unapply( [1/x,1/(x+y),1/y], x,y);

proc (x, y) options operator, arrow; [1/x, 1/(x+y),...

anonyme Funktionen

> data1:=[1,2,3,4,5]:

> data2:=map(x->x^2,data1);

data2 := [1, 4, 9, 16, 25]

> data3:=zip( (x,y)->[x,y], data1, data2);

data3 := [[1, 1], [2, 4], [3, 9], [4, 16], [5, 25]]...

> convert(data3,array);

MATRIX([[1, 1], [2, 4], [3, 9], [4, 16], [5, 25]])

> data:= [seq(rand(100)(),i=1..10)];

data := [55, 63, 57, 60, 74, 85, 16, 61, 7, 49]

> select( x->(x<50), data);

[16, 7, 49]

> tangente:=(f,x0)->unapply(D(f)(x0)*(x-x0)+f(x0),x);

tangente := proc (f, x0) options operator, arrow; u...

> tangente(x->x^2,2);

proc (x) options operator, arrow; 4*x-4 end proc

>

>

Prozeduren

> restart;

> f:=x->x^2;

f := proc (x) options operator, arrow; x^2 end proc...

> lprint(%);

proc (x) options operator, arrow; x^2 end

> f:=proc(x,n)
local i:
seq(x^i, i=1..n);
end:

> f(x,3);

x, x^2, x^3

> restart;

> diffn:=proc(f,n)
local i:
seq((D@@i)(f), i=1..n);
end:

> diffn(arctan, 4);

proc (a) options operator, arrow; 1/(1+a^2) end pro...

> sortreihe:=proc(liste)
local nums,syms,rest;
nums:=select(x->type(x,extended_numeric),liste);
syms:=select(x->type(x,symbol) or type(x,string),liste);
rest:=remove(x->(type(x,extended_numeric) or type(x,symbol) or type(x,string)),liste);
[ op(sort(nums)),op(sort(syms)),op(sort(rest))];
end proc:

> l:=[3,x,5,Pi,"Otto",u,sin(x),cos(x)+2];

l := [3, x, 5, Pi,

> sort(l);sortreihe(l);

[3, 5, x, sin(x), u,

[3, 5,

>

Abschnittsweise Definitionen

> f:=x->piecewise(x<0,2, x<1,x+2, x<2,3, x<3,5-x, 2);

f := proc (x) options operator, arrow; piecewise(x ...

> f(x);

PIECEWISE([2, x < 0],[x+2, x < 1],[3, x < 2],[5-x, ...

> f(2.6);

2.4

> int(f(x), x=0..3);

8

> fin:=unapply( int(f(x),x), x): fin(x);

PIECEWISE([2*x, x <= 0],[1/2*x^2+2*x, x <= 1],[3*x-...

> f1:=D(f):

> f1(x);

PIECEWISE([0, x < 0],[undefined, x = 0],[1, x < 1],...

> plot( [f,f1], -1..4, axes=boxed,discont=true,color=blue);

[Maple Plot]

> f2:=(D@@2)(f): f2(x);

PIECEWISE([undefined, x = 1],[undefined, x = 0],[un...

> f2a:=unapply(convert(f2(x),piecewise,x),x): f2a(x);

PIECEWISE([0, x < 0],[undefined, x = 0],[0, x < 1],...

> f2a(7);

0

> f:=convert(-signum(x)*abs(1-abs(x)), piecewise);

f := PIECEWISE([-1-x, x <= -1],[1+x, x < 0],[0, x =...

> plot(f, x=-2..2);

[Maple Plot]

> assume(r>0);

> f:=unapply( piecewise(x^2<=r^2, sqrt(r^2-x^2),0), x): f(x);

PIECEWISE([sqrt(r^2-x^2), x^2 <= r^2],[0, otherwise...

> plot(eval(f(x),r=3), x=-4..4);

[Maple Plot]

> convert(f(x),piecewise,x);

PIECEWISE([0, x <= -r],[sqrt(r^2-x^2), x <= r],[0, ...

> convert(f(x),Heaviside);

sqrt(r^2-x^2)*Heaviside(r+x)-sqrt(r^2-x^2)+sqrt(r^2...

> f:=x->piecewise(x<0,2, x<1,x+2, x<2,3, x<3,5-x, 2): f(x);

PIECEWISE([2, x < 0],[x+2, x < 1],[3, x < 2],[5-x, ...

> f1:=unapply( convert(f(x),Heaviside), x);

f1 := proc (x) options operator, arrow; 2+Heaviside...
f1 := proc (x) options operator, arrow; 2+Heaviside...

> plot(f1(x), x=-1..4);

[Maple Plot]

>

Zurück zum Inhaltsverzeichnis