Part 1. Functions and Graphs with MAPLE
Rovenski Vladimir, Haifa
Chapter 1 . Graphs of Tabular and Continuous Functions
> restart:
1.1 Basic Two-Dimensional Plot
> with(plots): # for example, command display from the library plots
Warning, existing definition for changecoords has been overwritten
Let the function
be given by the table of values (
,
), where
= 1, 2, ..., n.
For example,
Date: 12 13 14 15 16 17 18 19 20 21
Temp.: 15 17 17.5 19 20 19.5 18 17 17 19
> DateTemp:= [[12,15],[13,17],[14,17.5],[15,19],[16,20],[17,19.5],[18,18],[19,17],[20,17],[21,19]];
Plot the polygon through these points
> Line:=plot(DateTemp, labels=[T, D]): %;
Plot the points separately
> Points:=plot(DateTemp, style=point, symbol=circle): %;
Form arrays with x- and y-coordinates of the given points
> Days:=[seq(i+11, i=1..10)]; Temp:=[seq(op(2, DateTemp[i]), i=1..nops(Days))];
Transform the temperature from Celsius to Fahrenheit by the formula F=F(C) . (fix the number of to 3)
> Digits:=3:
> F := C -> evalf(9/5*C+32): map(F, Temp);
Plot the polygon LINE1 by the different method
> plot([seq([Days[i], Temp[i]], i=1..10)]);
Plot the diagram of vertical segments,
> p := i -> plot([[Days[i],0], [Days[i], Temp[i]]]):
> display([seq(p(i), i=1..10), Points]);
The command unapply(formulas, variables) transforms the formulas into functions of variables:
> f:=x^2: g:=unapply(f, x); g(2);
The command plot(expr, range, options) .
> plot(x^2, x=-2..2, scaling=constrained); # parabola
The option scaling = constrained (or clicking the button {1:1} ); see the right angles of a rectangle.
> plot([[0,0], [16,12], [13,16], [-3,4], [0,0]], scaling=constrained); # rectangle
Example where the same option sometimes does not allow one to see the graph
> plot(sin(x), x=0..50*Pi, numpoints=1999);plot(sin(x), x=0..50*Pi, numpoints=1999,scaling=constrained);
The command
plot( [
,...,
], range, color = [
, ...,
] ,...)
allows one to plot several graphs on one figure.
> f:=x^2: plot([f, diff(f,x)], x=-2..2,y=-.1..4, color=[blue,red], thickness=[2,1], linestyle=[1,2]);
Place text over a figure (and names of graphs) using the command textplot (and option title )
> graph := plot([-x/2, -x, -2*x, x/2, x, 2*x], x=-1..1, y=-1..1): text:=plots[textplot]({[1,.5, `y=x/2`], [1,1, `y=x`], [.4,1, `y=2x`], [-.4,1, `y=-2x`], [-1,1, `y=-x`], [-1,.5,`y=-x/2`]}, align=ABOVE): display([graph, text], font=[TIMES, ROMAN, 18]);
Exercise 2.
1. Solve graphically and analytically the equation = .
> restart: plot([exp(-x), sin(x)], x=0..Pi);
The root, 0.58
> fsolve(exp(-x)-sin(x)=0);
The second root, 3.09
> fsolve(exp(-x)-sin(x)=0, x, 1..5);
2. From a piece of pasteboard 4 in. x 5 in. construct a rectangular box without a roof having maximal volume.
> V:=x -> x*(4-2*x)*(5-2*x): plot(V(x), x=0..2);
Solve the equation that sets the derivative of the polynomial equal to zero.
> Vx:=simplify(diff(V(x), x)); fsolve(Vx,x); subs(x=%[1],V(x));
4. Plot the graph of the rational function y = and decompose it into partial fractions.
> f:=x->(x^6-x^2+1)/(x^5-6*x^4+12*x^3-12*x^2+11*x-6);
> plot(f(x), x=0.5..4, y=-200..200, discont=true);
> convert(f(x), parfrac, x);
Compare the results of the following commands and state your conclusions.
> plot(tan, -Pi..Pi);
> plots[display](%, view=[-4..4, -10..10], xtickmarks=[-3.14=`-Pi`, -1.57=`-Pi/2`, 1.57=`Pi/2`, 3.14=`Pi`]);
The square diagram " colors ".
> P:=seq(seq(plots[polygonplot]([[i,j],[i+1,j],[i+1,j+1],[i,j+1]], color=COLOR(RGB, 0.1*i,0.1*j,0)), i=0..10), j=0..10):
> plots[display]({P}, scaling=constrained,labels=[`R`,`G`], title=`RGB color(R,G,0)`, tickmarks=[[seq(i+0.5=`.`||i, i=0..9), 10.5=`1`], [seq(j+0.5=`.`||j, j=0..9), 10.5=`1`]]);
The diagram " width of line " (analogously for " type of line ").
> for i from 0 to 15 do thick[i]:=plot(i, x=0..1, thickness=i) od:
> plots[display](convert(thick, set), axes=boxed, tickmarks=[0,15], title=`thickness option: [0,1,..,15]`);
The option filled=true paints in the domain between the graph and the axis OX.
> sine:=plot(sin, 0..4*Pi, color=black, thickness=3):
>
s:=plot(sin, 0..4*Pi, filled=true, color=red):
cosine:=plot(cos, 0..4*Pi, color=black, thickness=3):
> c:=plot(cos, 0..4*Pi, filled=true, color=red):
> f:=x->if cos(x)>0 and sin(x)>0 then min(cos(x),-sin(x)) elif cos(x)<0 and sin(x)<0 then max(cos(x), -sin(x)) else 0 fi: b:=plot(f, 0..4*Pi, filled=true, color=white):
> plots[display]([sine, cosine, b, s, c], scaling=constrained);
The table of graphs.
> plots[display](array([sine, cosine]),scaling=constrained); # row of plots
> plots[display](array(1..2, 1..1, [[sine], [cosine]])); # lines of plots
The symbol @ for the composition of functions f @ g, plot iterations of the given function.
> n:=8: q:=i->plot((sin@@i)(x), x=0..2*Pi, color=COLOR(RGB, 1/i, 0, 1-1/i)): plots[display]([seq(q(i), i=1..n)]);
Taylor decomposition . Compare Taylor polynomials of a function with the given function.
> x1:=3*Pi: p[0]:=plot(sin(x), x=0..x1, thickness=2):
> for i from 1 to 9 do pp:=convert(taylor(sin(x), x=0, 2*i-1), polynom): p[i]:=plot(pp, x=0..x1, y=-3..3) od:
> plots[display]([seq(p[i], i=0..9)], scaling=constrained);
A set of equations and inequalities
> plots[inequal]({a+b>3, 2.01*b-a<6, 3*a+2.01*b>5, -b+a<=8}, a=-10..30, b=-10..15, optionsfeasible=(color=red), optionsopen=(color=blue, thickness=2), optionsclosed=(color=green, thickness=3), optionsexcluded=(color=yellow));
1.2. Graphs of Functions Obtained from Elementary Functions
First plot graphs of the following functions (set
for functions 1-5).
1.
Catenary
y =
is similar to a parabola. A catenary is obtained hanging a cord by its ends between two poles.
> plot(cosh(x), x=-1..1);
2. Witch of Agnesi ( versiera ) .
> plot(1/(1+x^2), x=-infinity..infinity);
3. Cycloid - .
> plot(arccos(1-y)-sqrt(2*y-y^2), y=0...3);
4. Tractrix ,
> plot(ln(1-sqrt(1-y^2)/y+sqrt(1-y^2)), y=0.1..1, scaling=constrained); `
5. Dinostratus' quadratrix .
> plot(x*cot(Pi*x)/2, x=-1/2..1/2, scaling=constrained);
6. Beats . .
>
p:=plot(6*sin(x/4)*sin(4*x), x=-Pi..9*Pi): q:=i->plot(6*i*sin(x/4),x=-Pi..9*Pi, linestyle=2):
plots[display]([p, q(-1), q(1)],scaling=constrained);
7. Curve of
damped oscillations
y = A exp(-kx) sin(
x+a).
For k = 0 the oscillations are periodic (without resistance of the medium). Also plot this graph with the option
x = 0..infinity
.
> p:=plot(exp(1)^(-x/2)*sin(4*x), x=0..3*Pi): q:=i->plot(i*exp(1)^(-x/2), x=0..3*Pi, linestyle=2): plots[display]([p, q(-1), q(1)]);
8. A remarkable limit , (or ).
> limit(sin(x)/x, x=0); plot(sin(x)/x, x=-10..10);
A sequence is a function on N. We calculate the sequence for n = 12 ..16 and compare with the previous results.
> f:=n->n*sin(1/n): L:=evalf(seq([n, f(n)], n=12..16));
> plot([L], style=point, symbol=circle); Digits:=14: evalf(f(1000000));
> n:='n': limit(f(n), n=infinity);
> Digits:=4:
Let us plot a diagram showing the sequence of prime numbers .
> PN:=[seq([i, ithprime(i)], i=1..9)]: plot(PN, style=point, symbol=box);
9. Growth curves
1). Logarithmic parabola y = , (b, c > 0).
> f:=x->b^x*c^(x^2): plot(subs(b=2, c=2, f(x)), x=-2..1);
2). Logarithmic curve y = (k, a, b > 0).
> f:=x->k/(1+b*exp(-a*x)): plot(subs(k=2, b=0.2, a=1,[f(x), k]), x=-7..3, linestyle=[1, 2]);
The line is the horizontal asymptote, is the point of inflection.
3). Growth curves of Gompertz y = (a, b > 0) .
> f:=x->a^(b^x): plot({subs(b=0.5, a=1.2, f(x)), 1},x=-4..1, y=0..18, linestyle=[1, 2]);
1.3 . Graphs of Special Functions
1. The incomplete Gamma function y = (x, z) =
Gamma function y = (x) = has vertical asymptotes at the points of discontinuity , (n = 0, 1, 2, ... )
> plot(GAMMA(x), x=-4..5, y=-10..10);
2. Integral of probabilities y = erf(x) = ( error function ) is derived using Taylor series.
> convert(taylor(erf(x), x=0, 31), polynom); plot([erf(x),1,-1], x=-2..2, linestyle=[1,2,2]);
3. Exponential Integral function
> plot([seq(Ei(n,x), n=0..5)], x=-.2..1.6, y=0..1);
4. Sine Integral function y = Si(x) = . This function is derived using Taylor series, its horizontal asymptote is y = .
> plot([Si(x), Pi/2], x=-1..20, y=0..2, linestyle=[1,2]);
Cosine Integral function y = Ci(x) = + + . Here = 0.57721 is the Euler constant ; the horizontal asymptote is y = 0.
> plot(Ci(x), x=-3..21, y=-0.5..0.5);
5. Elliptic integrals of the first and second kinds.
> plot([[1, t, t=0..4], EllipticK(x)], x=0..1.2, y=0..4);
> plot([[1, t, t=0..4], EllipticE(x)], x=0..1.2, y=0..4);
1.4. Transformations of Graphs
The animatecurve function (from the library plots )
> plots[animatecurve]({x-x^3, sin(x)}, x=0..Pi/2);
Play with simple transformations 1-6 of the graph of a function using the command animate .
> with(plots): f:= x->x^2;
Warning, existing definition for changecoords has been overwritten
1. Parallel translation in the direction of an arbitrary vector.
> X:=2: Y:=6: p1:=plottools[arrow]([0,0], [X,Y], .1, .2, .1): p2:=animate([x+t, f(x)+3*t, x=-2.5..2.5], t=0..2): display([p1, p2]);
2. Contraction along the axis OX.
>
p1:=plot([cos(u), sin(u), u=0..2*Pi]): p2:=animate([t*cos(u), sin(u), u=0..2*Pi], t=1..2):
p3:=animate([t*x, f(x)+2, x=-2..2], t=1..2): display([p1,p2,p3],scaling=constrained);
3. Contraction along the axis OY.
>
p4:=plot([cos(u), sin(u), u=0..Pi]):
p5:=animate([cos(u), t*sin(u), u=0..Pi], t=1..2):
p6:=animate(t*f(x), x=-2..2, t=1..2):
display([p4, p5, p6], scaling=constrained);
4. Symmetry with respect to the axis OX.
>
s1:=animate([t*x, f(x), x=0..2], t=-1..1, color=green):
s2:=animate([t*x, f(x), x=-2..0], t=-1..1, color=blue):
s3:=animate([t*x, f(1), x=0..1], t=-1..1, color=green):
s4:=animate([t*x, f(1), x=-1..0], t=-1..1, color=blue):
display([s1, s2, s3, s4]);
5. Symmetry with respect to the axis OY.
>
s5:=animate([2, t*x*f(2), x=0..1], t=-1..1, color=blue):
s6:=animate([x, t*f(x), x=-2..2], t=-1..1, color=green):
display([s5, s6]);
6. Symmetry with respect to the origin of coordinates.
>
s7:=animate([t*x,-t*f(x),x=0..2], t=-1..1, color=green):
s8:=animate([t*x, -t*f(x), x=-2..0], t=-1..1, color=red):
s9:=animate([2*t*x,t*x*f(2),x=-1..0], t=-1..1, color=red):
display([s7, s8, s9]);
Example.
1. The power function y = and its inverse y = .
>
p1:=plot([surd(x, 3), x^3], x=-2..8, y=-2..8):
p2:=plots[textplot]({[3, 8, `y=x^3`], [6, 8,`y=x`], [7, 3, `y=x^(1/3)`]}):
p3:=plot(x, x=-2..8, y=-2..8, style=POINT):
display([p1, p2, p3]);
2. The inverse function for , - /2 < x <
>
p1:=plot(Pi-arcsin(x), x=-1..1):
p2:=plot(sin(x), x=Pi/2..3*Pi/2):
p3:=plot(x, x=-1..3*Pi/2, style=point):
p4:=plots[textplot]({[3, 0.5, `y=sin(x)`],[.5, 3.5,`y=Pi-arcsin(x)`]},align=RIGHT):
display([p1, p2, p3, p4]);