Chapter 19
> with(plots):
plotting functions
> plot(sin);
> plot(sin, -10..10);
> 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);
> plot( x/(x^2-1), x=-2..3);
> plot( x/(x^2-1), x=-2..3, -10..10);
> plot( x/(x^2-1), x=-2..3, -10..10,discont=true, color=black);
> plot( {x,1+x^2,2+x^x}, x=0..infinity, 0..infinity);
> plot( sin(x^3), x=1..5,numpoints=1500);
> plot( subs(a=1, b=-2, c=2, a*x^2+b*x+c), x=0..3);
> 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
> plot( 'f(x)', x=-2..5);
> 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);
plotting parametric functions
> plot( [ t*cos(t), t*sin(t), t=0..6*Pi], scaling=constrained );
> plot( [ sin(phi)*sin(3*phi), phi,phi=0..2*Pi],coords=polar );
plotting implicit functions
> with(plots):
> implicitplot( x^2-x=y^3-3*y, x=-3..3, y=-2..3);
> implicitplot( (x,y)-> x^2-x-y^3+3*y, -3..3, -2..3);
> implicitplot( sin(x*y), x=-3..5, y=0..10, grid=[80,80]);
points and lines
> plot( [[1,1], [2,2], [3,2], [4,1]] );
> plot(sin(x),x=0..2*Pi, style=point);
> data:=seq( [rand(100)(),rand(100)()], n=1..100):
> plot( [data], style=point );
> listplot( [data], style=point );
> pointplot( [data] );
displaying multiple plots
> f:=x+sin(x): df:=diff(f,x):
> x0:=evalf(solve(df=1));
> y0:=evalf(subs( x=x0, f));
> p1:=plot(x+sin(x), x=0..4):
> p2:=plot( [[x0-0.5, y0-0.5], [x0+0.5, y0+0.5]] ):
> display( [p1, p2], scaling=constrained);
> datax:=[seq(i*0.3,i=1..20)]:
> datay:=map(sin, datax):
> data:=zip( (x,y)->[x,y], datax, datay):
> with(share): readshare(fit,numerics):
See ?share and ?share,contents for information about the share library
> f:=fit( datax, datay, [1,x,x^2, x^3], x);
> p1:=plot( data, style=point):
> p2:=plot( f, x=0..6):
> display( [p1,p2] );
> restart: with(plots):
>
p1:=plot(sin(x),x=-Pi..Pi,-1..1):
p2:=plot(cos(x),x=-Pi..Pi):
p3:=plot(sinh(x),x=-Pi..Pi):
p4:=plot(cosh(x),x=-Pi..Pi):
> display(array(1..2,1..2,[[p1,p2],[p3,p4]]) );
> p1;p2;p3;p4;
>
labelling plots
> plot( sin(x), x=0..2*Pi, title=`Sinus function`,labels=[`x Axis`, `y Axis`]);
> p1:=plot(sin(x), x=0..2*Pi):
> p2:=textplot([3*Pi/2, 0.5,`sin(x)`] ):
> display( [p1, p2] );
> display( [p1, p2], font=[TIMES, ITALIC, 50],axesfont=[TIMES,ROMAN,30]);
options
> plot( [seq(sin(x+n*Pi/8),n=1..3)], x=0..2*Pi, thickness=[1,2,3], color=black);
> plot( [seq(sin(x+n*Pi/8),n=1..4)], x=0..2*Pi, linestyle=[1,2,3,4], color=black);
>
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);
> implicitplot( x^2+y^2=1, x=-1..1, y=-1..1);
> implicitplot( x^2+y^2=1, x=-1..1, y=-1..1, scaling=constrained);
> 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);