Kapitel 19
> with(plots):
Verschiedene Varianten für Funktionen und Terme
Funktion
> plot(sin);
> plot(sin, -10..10);
Term
> plot(sin(x), x=-10..10);
> plot( {sin(x), x^2/20}, x=0..2*Pi);
> plot( {seq(sin(n*x)/n, n=1..5)}, x=0..Pi);
>
Sonderfall Singularität
> plot( x/(x^2-1), x=-2..3,numpoints=500);
Maple verwendet einen adaptiven Algorithmus, der um so genauer rechnet, je mehr sich die Funktion ändert.
>
Dieser Algorithmus lässt sich so abschalten:
> plot( x/(x^2-1), x=-2.1..2.95, adaptive=false);
>
So vermeidet man die Singularitäten mit Sicherheit:
> plot( x/(x^2-1), x=-2.1..2.95, adaptive=false,sample=[-2,-1/2,0,1/2,2]);
>
Die gängige Methode, eine vernünftige Darstellung trotz Singularitäten zu bekommen, ist die Einschränkung des vertikalen Bereichs:
> plot( x/(x^2-1), x=-2..3, -10..10);
>
Mit Unterdrückung der 'Polgeraden':
> plot( x/(x^2-1), x=-2..3, -10..10,discont=true, color=black);
>
Unendliche Plotbereiche
> plot( {x,1+x^2,2+x^x}, x=0..infinity, 0..infinity);
>
Auflösung gefragt:
> plot( sin(x^3), x=1..5,numpoints=1500);
>
In Plots können nur Zahlen verarbeitet werden:
> plot( a*x^2+b*x+c, x=0..3);
Plotting error, empty plot
>
> plot( subs(a=1, b=-2, c=2, a*x^2+b*x+c), x=0..3);
>
Fallunterscheidungen müssen zur rechten Zeit getroffen werden:
> f:=proc(x) if x>0 then sin(x) else x fi end:
> plot( f(x), x=-2..5);
Error, (in f) cannot evaluate boolean: -x < 0
> plot( 'f(x)', x=-2..5);
>
Imaginäre Größen bleiben unsichtbar:
> plot( sin(I*x), x=-1..1);
Plotting error, empty plot
> plot( { Re(sin(1+I*x)), Im(sin(1+I*x)) }, x=-2..2);
>
>
Vor allem für Physiker interessant. Denn wo kommt in der Realität eine Kurve vor, die sich mit einer eindeutigen Funktion im x-y-Koordinatensystem beschreiben lässt?
> restart:
> plot( [ t*cos(t), t*sin(t), t=0..6*Pi], scaling=constrained );
>
Alternative:
> plot(x,x=0..6*Pi,coords=polar, scaling=constrained);
>
> plot( [ sin(phi)*sin(3*phi), phi,phi=0..2*Pi]);
>
>
> plot( [[ sin(phi)*sin(3*phi)+phi, -sin(phi)*sin(3*phi)+phi,phi=0..2*Pi],[x,x,x=0..2*Pi]],scaling=constrained,color=black,numpoints=500);
>
>
Phasendiagramme
>
Zur Übung
> x:=t->t^2;
> y:=t->sin(t);
> plot([x(t),t,t=0..2]);
> plot([t,x(t),t=0..2]);
>
> plot([y(t),x(t),t=0..2]);
Experimentieren Sie mit eigenen Belegungen für x und y!
>
>
In anderen Koordinaten:
> plot( [ sin(phi)*sin(3*phi), phi,phi=0..2*Pi],coords=polar );
>
> plot( [[ sin(phi)*sin(3*phi)+phi, -sin(phi)*sin(3*phi)+phi,phi=0..2*Pi],[x,x,x=0..2*Pi]],scaling=constrained, coords=polar,numpoints=500);
>
>
Koordinatensysteme (2D)
Es gibt 15 Koordinatensysteme (2D)
>
>
>
co:= [bipolar, cardioid, cartesian, cassinian, elliptic, hyperbolic, invcassinian, invelliptic, logarithmic, logcosh, maxwell, parabolic, polar, rose, tangent];
>
So sieht die 1 in den verschiedenen Koordinatensystemen aus. Experimentieren Sie mit IHRER Funktion:
> with(plots):
>
for c in co do
plot(1,x=-Pi..Pi, numpoints=500, coords=c, title=c, scaling=constrained) od;
>
>
>
for c in co do
p[c]:=plot(1,x=-Pi..Pi, numpoints=500, coords=c, title=c) od:
>
> #p[elliptic];
>
All together now:
> plots[display]([seq(p[c],c=co)]);
>
>
> #?plotsetup
> #plotsetup(help);
Die nächsten Befehle erzeugen 15 neue Fenster
> plotsetup(window);
>
for c in co do
coordplot(c,[-4..4,-Pi..Pi],title=c,scaling=constrained) od;
Jetzt wieder inline.
> plotsetup(default);
>
Für eine angepasste Darstellung ist oft view[..] erforderlich
>
ks:=coordplot(polar,[0..3,0..2*Pi],grid=[10,20],scaling=constrained,view=[-3..3,-3..3]):ks;
> spir:=plot(0.05*x,x=0..20*Pi,coords=polar,thickness=2,color=black,numpoints=500,scaling=constrained):spir;
> display(ks,spir);
>
>
>
>
>
>
Implizit gegebene Funktionen zeichnen
Wenn man keine explizite Formulierung kennt, oder wenn sie zu kompliziert wird, können Zusammenhänge mit implicitplot gezeigt werden.
> with(plots):
Warning, the name changecoords has been redefined
> implicitplot( x^2-x=y^3-3*y, x=-3..3, y=-2..3);
Oder:
> #implicitplot( (x,y)-> x^2-x-y^3+3*y, -3..3, -2..3);
>
Das wäre nicht so angenehm:
> solve(x^2-x=y^3-3*y,y);
>
Implicitplot arbeitet numerisch:
> implicitplot( sin(x*y), x=-3..5, y=0..10);
Und benötigt manchmal eine hörere Auflösung
> implicitplot( sin(x*y), x=-3..5, y=0..10, grid=[80,80]);
>
>
>
> plot( [[1,1], [2,2], [3,2], [4,1]] );
> plot(sin(x),x=0..2*Pi, style=point, symbolsize=20,color=black);
> data:=seq( [rand(100)(),rand(100)()], n=1..100):
> plot( [data], style=point );
>
Alternativen
> plots[listplot]( [data], style=point );
> plots[pointplot]( [data] );
>
Jeder plot-Befehl erzeugt eine 'Plotstruktur'. Mit display können diese Strukturen erneut angezeigt werden - modifiziert oder zusammen mit anderen.
>
> restart:with(plots):
Warning, the name changecoords has been redefined
> f:=x->x+sin(x); df:=D(f);
> x0:=solve(df(x)=1);
>
Gibt man einem Plot einen Namen, so sollte man den Befehl mit einem Doppelpunkt abschließen, weil sonst die Plotstruktur nicht gezeichnet, sondern ausgedruckt wird.
> p1:=plot(f(x), x=0..4,color=black):
> p2:=plot( [[x0-0.5, f(x0)-0.5*df(x0)], [x0+0.5,f(x0)+0.5*df(x0)]] ):
> display( [p1, p2], scaling=constrained);
>
>
> x0:=solve(df(x)=s,x);
> display(seq({p1,plot( [[x0-0.5, f(x0)-0.5*df(x0)], [x0+0.5,f(x0)+0.5*df(x0)]] )},s=[2,1,1/2,1/3,1/4]),view=[-1..4,-1..4]);
> display(seq(display(p1,plot( [[x0-0.5, f(x0)-0.5*df(x0)], [x0+0.5,f(x0)+0.5*df(x0)]],thickness=2 )),s=[2,1,1/2,1/3,1/4]),view=[-1..4,-1..4], insequence=true);
>
>
Ein Beispiel aus der Statistik
> datax:=[seq(i*0.3,i=1..20)]:
> datay:=map(sin, datax):
> data:=zip( (x,y)->[x,y], datax, datay):
>
> with(stats):
> f:=rhs(fit[leastsquare[[x,y],y=d*x^3+a*x^2+b*x+c]]([datax,datay]));
>
> p1:=plot( data, style=point):
> p2:=plot( f, x=0..6):
> display( [p1,p2] );
>
>
Mehrere Bilder in einem Array
> restart: with(plots):
Warning, the name changecoords has been redefined
>
p1:=plot(sin(x),x=-Pi..Pi,-1..1,color=black):
p2:=plot(cos(x),x=-Pi..Pi,color=black):
p3:=plot(sinh(x),x=-Pi..Pi,color=black):
p4:=plot(cosh(x),x=-Pi..Pi,color=black):
> display(array(1..2,1..2,[[p1,p2],[p3,p4]]),tickmarks=[2,3] );
>
>
> plot( sin(x), x=0..2*Pi, title=`Sinusfunktion`,labels=[`x-Achse`, `y-Achse`],color=black);
> p1:=plot(sin(x), x=0..2*Pi):
> p2:=textplot([3*Pi/2, 0.5,`sin(x)`] ):
> display( [p1, p2] );
>
Für die Ausgabe in Postscript
> display( [p1, p2], font=[TIMES, ITALIC, 50],axesfont=[TIMES,ROMAN,30]);
>
Linienstärken
> plot( [seq(sin(x+n*Pi/8),n=1..3)], x=0..2*Pi, thickness=[1,2,5], color=black);
>
> plot( [seq(sin(x+n*Pi/8),n=1..5)], x=0..2*Pi, linestyle=[1,2,3,4,5], color=black);
>
> plot( [seq(sin(x+n*Pi/8),n=1..5)], x=0..2*Pi, linestyle=[1,2,3,4,5], color=[red,green,blue,yellow,black]);
>
>
Legende mit Kontextmenü erzeugt
> plot( [seq(sin(x+n*Pi/8),n=1..5)], x=0..2*Pi, linestyle=[1,2,3,4,5], color=[red,green,blue,yellow,black]);
>
Legende im Plotbefehl
> plot( [seq(sin(x+n*Pi/8),n=1..5)], x=0..2*Pi, linestyle=[1,2,3,4,5], color=[red,green,blue,yellow,black],legend=[a,b,c,d,e]);
>
>
Style, Symbol und Symbolgröße
> plot(x,x,style=point,symbolsize=20);
>
Das Symbol Point ist wirklich ein Punkt
>
plot( [seq(sin(x+n*Pi/4),n=1..5)], x=0..2*Pi, style=point,
symbol=[BOX, CROSS, CIRCLE, DIAMOND, POINT], color=black, numpoints=100,symbolsize=[10,12,14,16,20]);
>
Gefüllt
> plot([cos(x),sin(x)],x=-2*Pi..2*Pi,filled=true,color=[grey,yellow]);
>
>
Maßstab
> display(plot(x,x=-1..1),implicitplot( x^2+y^2=1, x=-1..1, y=-1..1));
>
> display(%,scaling=constrained);
>
Die Option view
> implicitplot( x^2+y^2=1, x=-1..1, y=-1..1,view=[-1..1,-2..2],color=black);
> implicitplot( x^2+y^2=1, x=-2..2, y=-1..1, view=[-2..2,-1..1], scaling=constrained,color=black,tickmarks=[2,2]);
Achsen
> plot( [ sin(3*t), cos(5*t), t=0..2*Pi ], axes=boxed);
> plot( [ sin(3*t), cos(5*t), t=0..2*Pi ], axes=frame);
>
>
>