Kapitel 11
> restart;
Terme
> f:=x^2-3*x;
> f1:=2*diff(f,x);
> eval(f1,x=3);
Funktionen
> restart;
> f:=x->x^2-3*x;
> f(x), f(sin(y)), f(25.77);
> diff(f(x),x);D(f);
> g:=(x,y,z)->(x^y)^z;
> g(a,b,c), g(2,3,4);
> f:=x->x^2; g:=y->y^3;
> (f+2*g)(z), (f*g)(z), (f@g)(z);
> f:=x->(x,1+1/x);
> g:=(x,y)->(x^2/y,y^2/x);
> f(3), (g@f)(3);
> wertetab:=f->[seq([i,f(i)],i=-3..3)];
> wertetab(x->x^2);
>
>
unapply
> f:=x->1/(1+x^2): f1:=x->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(1);
> unapply(a*x^2+b*y^2+c*z^2,x,y,z);
> unapply( [1/x,1/(x+y),1/y], x,y);
anonyme Funktionen
> data1:=[1,2,3,4,5]:
> data2:=map(x->x^2,data1);
> data3:=zip( (x,y)->[x,y], data1, data2);
> convert(data3,array);
> data:= [seq(rand(100)(),i=1..10)];
> select( x->(x<50), data);
> tangente:=(f,x0)->unapply(D(f)(x0)*(x-x0)+f(x0),x);
> tangente(x->x^2,2);
>
>
Prozeduren
> restart;
> f:=x->x^2;
> 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);
> restart;
>
diffn:=proc(f,n)
local i:
seq((D@@i)(f), i=1..n);
end:
> diffn(arctan, 4);
>
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];
> sort(l);sortreihe(l);
>
Abschnittsweise Definitionen
> f:=x->piecewise(x<0,2, x<1,x+2, x<2,3, x<3,5-x, 2);
> f(x);
> f(2.6);
> int(f(x), x=0..3);
> fin:=unapply( int(f(x),x), x): fin(x);
> f1:=D(f):
> f1(x);
> plot( [f,f1], -1..4, axes=boxed,discont=true,color=blue);
> f2:=(D@@2)(f): f2(x);
> f2a:=unapply(convert(f2(x),piecewise,x),x): f2a(x);
> f2a(7);
> f:=convert(-signum(x)*abs(1-abs(x)), piecewise);
> plot(f, x=-2..2);
> assume(r>0);
> f:=unapply( piecewise(x^2<=r^2, sqrt(r^2-x^2),0), x): f(x);
> plot(eval(f(x),r=3), x=-4..4);
> convert(f(x),piecewise,x);
> convert(f(x),Heaviside);
> f:=x->piecewise(x<0,2, x<1,x+2, x<2,3, x<3,5-x, 2): f(x);
> f1:=unapply( convert(f(x),Heaviside), x);
> plot(f1(x), x=-1..4);
>