> plot( [(x^3+1)/x, x^2], x=-3..3,
y=-9..9,
color=[red,blue],
thickness=3,
style=[line,point],
symbol=point,
numpoints=100,
scaling=unconstrained );
# Program: sketch y=f(x) and see all its bends (turns)
> draw := proc()
local f,type,soln,n,i,j,r,m,M,d;
m :=
10^10;
M := -10^10;
printf("Enter a function in terms of
x:\n");
f := scanf("%a")[1];
type := [ solve(f,x) ];
for i from 1 to nops(type) do
soln := [ evalf( allvalues( type[i],'independent' ) ) ];
#print(soln);
n := nops( soln );
printf("type %d: # soln= %d, real part:", i,n);
for j from 1 to n do
r := Re( evalf(soln[j]) );
printf(" %f,",r);
if r > M then M := r; fi;
if r < m then m := r; fi;
od;
printf("\n");
od;
if M>m then d:=(M-m)/4; else d:=5; fi;
printf("m=%f, d=%f, M=%f\n",
m,d,M );
printf("X-range: %f .. %f\n",
m-d,M+d );
plot(f,x=m-d..M+d);
end:
# Execute the program:
> draw();
Enter a function in terms of x:
> x^5-x^3+x-1
type 1: # soln= 1, real part: 1.000000,
type 2: # soln= 4, real part: .518913, .518913, -1.018913,
-1.018913,
m=-1.018913, d=.504728, M=1.000000
X-range: -1.523641 .. 1.504728
# Program: show graphs of functions in the same view rectangle
> sin2i := proc()
local pic, i, n;
with(plots);
printf("Enter n to see graphs of
{y=sin(x)^i, x=0..Pi} for i=1 to n:\n");
n := scanf("%d")[1];
for i from 1 to n do
pic[i] := plot(sin(x)^i, x=0..Pi);
od;
display( [ pic[j] $j=1..n ] ); # j cannot
be declaired!
end:
# Execute the program:
> sin2i();
Enter n to see graphs of {y=sin(x)^i, x=0..Pi} for i=1 to n:
> 20