ROV01_6.MWS

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 [Maple Math] be given by the table of values ( [Maple Math] , [Maple Math] ), where [Maple Math] = 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]];

[Maple Math]

Plot the polygon through these points

> Line:=plot(DateTemp, labels=[T, D]): %;

[Maple Plot]

Plot the points separately

> Points:=plot(DateTemp, style=point, symbol=circle): %;

[Maple Plot]

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))];

[Maple Math]

[Maple Math]

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);

[Maple Math]

Plot the polygon LINE1 by the different method

> plot([seq([Days[i], Temp[i]], i=1..10)]);

[Maple Plot]

Plot the diagram of vertical segments,

> p := i -> plot([[Days[i],0], [Days[i], Temp[i]]]):

> display([seq(p(i), i=1..10), Points]);

[Maple Plot]

The command unapply(formulas, variables) transforms the formulas into functions of variables:

> f:=x^2: g:=unapply(f, x); g(2);

[Maple Math]

[Maple Math]

The command plot(expr, range, options) .

> plot(x^2, x=-2..2, scaling=constrained); # parabola

[Maple Plot]

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

[Maple Plot]

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);

[Maple Plot]

[Maple Plot]

The command plot( [ [Maple Math] ,..., [Maple Math] ], range, color = [ [Maple Math] , ..., [Maple Math] ] ,...) 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]);

[Maple Plot]

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]);

[Maple Plot]

Exercise 2.

1. Solve graphically and analytically the equation [Maple Math] = [Maple Math] .

> restart: plot([exp(-x), sin(x)], x=0..Pi);

[Maple Plot]

The root, 0.58

> fsolve(exp(-x)-sin(x)=0);

[Maple Math]

The second root, 3.09

> fsolve(exp(-x)-sin(x)=0, x, 1..5);

[Maple Math]

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);

[Maple Plot]

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));

[Maple Math]

[Maple Math]

[Maple Math]

4. Plot the graph of the rational function y = [Maple Math] 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);

[Maple Math]

> plot(f(x), x=0.5..4, y=-200..200, discont=true);

[Maple Plot]

> convert(f(x), parfrac, x);

[Maple Math]

Compare the results of the following commands and state your conclusions.

> plot(tan, -Pi..Pi);

[Maple Plot]

> plots[display](%, view=[-4..4, -10..10], xtickmarks=[-3.14=`-Pi`, -1.57=`-Pi/2`, 1.57=`Pi/2`, 3.14=`Pi`]);

[Maple Plot]

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`]]);

[Maple Plot]

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]`);

[Maple Plot]

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);

[Maple Plot]

The table of graphs.

> plots[display](array([sine, cosine]),scaling=constrained); # row of plots

[Maple Plot]

> plots[display](array(1..2, 1..1, [[sine], [cosine]])); # lines of plots

[Maple Plot]

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)]);

[Maple Plot]

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);

[Maple Plot]

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));

[Maple Plot]

1.2. Graphs of Functions Obtained from Elementary Functions

First plot graphs of the following functions (set [Maple Math] for functions 1-5).
1.
Catenary y = [Maple Math] is similar to a parabola. A catenary is obtained hanging a cord by its ends between two poles.

> plot(cosh(x), x=-1..1);

[Maple Plot]

2. Witch of Agnesi ( versiera ) [Maple Math] .

> plot(1/(1+x^2), x=-infinity..infinity);

[Maple Plot]

3. Cycloid [Maple Math] - [Maple Math] .

> plot(arccos(1-y)-sqrt(2*y-y^2), y=0...3);

[Maple Plot]

4. Tractrix [Maple Math] ,

> plot(ln(1-sqrt(1-y^2)/y+sqrt(1-y^2)), y=0.1..1, scaling=constrained); `

[Maple Plot]

5. Dinostratus' quadratrix [Maple Math] .

> plot(x*cot(Pi*x)/2, x=-1/2..1/2, scaling=constrained);

[Maple Plot]

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);

[Maple Plot]

7. Curve of damped oscillations y = A exp(-kx) sin( [Maple Math] 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)]);

[Maple Plot]

8. A remarkable limit [Maple Math] , (or [Maple Math] ).

> limit(sin(x)/x, x=0); plot(sin(x)/x, x=-10..10);

[Maple Math]

[Maple Plot]

A sequence [Maple Math] is a function on N. We calculate the sequence [Maple Math] 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));

[Maple Math]

> plot([L], style=point, symbol=circle); Digits:=14: evalf(f(1000000));

[Maple Plot]

[Maple Math]

> n:='n': limit(f(n), n=infinity);

[Maple Math]

> 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);

[Maple Plot]

9. Growth curves

1). Logarithmic parabola y = [Maple Math] [Maple Math] , (b, c > 0).

> f:=x->b^x*c^(x^2): plot(subs(b=2, c=2, f(x)), x=-2..1);

[Maple Plot]

2). Logarithmic curve y = [Maple Math] (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]);

[Maple Plot]

The line [Maple Math] is the horizontal asymptote, [Maple Math] is the point of inflection.

3). Growth curves of Gompertz y = [Maple Math] (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]);

[Maple Plot]

1.3 . Graphs of Special Functions

1. The incomplete Gamma function y = [Maple Math] (x, z) = [Maple Math]

Gamma function y = [Maple Math] (x) = [Maple Math] has vertical asymptotes at the points of discontinuity [Maple Math] , (n = 0, 1, 2, ... [Maple Math] )

> plot(GAMMA(x), x=-4..5, y=-10..10);

[Maple Plot]

2. Integral of probabilities y = erf(x) = [Maple Math] [Maple Math] ( 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]);

[Maple Math]
[Maple Math]

[Maple Plot]

3. Exponential Integral function

> plot([seq(Ei(n,x), n=0..5)], x=-.2..1.6, y=0..1);

[Maple Plot]

4. Sine Integral function y = Si(x) = [Maple Math] . This function is derived using Taylor series, its horizontal asymptote is y = [Maple Math] .

> plot([Si(x), Pi/2], x=-1..20, y=0..2, linestyle=[1,2]);

[Maple Plot]

Cosine Integral function y = Ci(x) = [Maple Math] + [Maple Math] + [Maple Math] . Here [Maple Math] = 0.57721 is the Euler constant ; the horizontal asymptote is y = 0.

> plot(Ci(x), x=-3..21, y=-0.5..0.5);

[Maple Plot]

5. Elliptic integrals of the first and second kinds.

> plot([[1, t, t=0..4], EllipticK(x)], x=0..1.2, y=0..4);

[Maple Plot]

> plot([[1, t, t=0..4], EllipticE(x)], x=0..1.2, y=0..4);

[Maple Plot]

1.4. Transformations of Graphs

The animatecurve function (from the library plots )

> plots[animatecurve]({x-x^3, sin(x)}, x=0..Pi/2);

[Maple Plot]

Play with simple transformations 1-6 of the graph of a function [Maple Math] using the command animate .

> with(plots): f:= x->x^2;

Warning, existing definition for changecoords has been overwritten

[Maple Math]

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]);

[Maple Plot]

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);

[Maple Plot]

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);

[Maple Plot]

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]);

[Maple Plot]

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]);

[Maple Plot]

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]);

[Maple Plot]

Example.

1. The power function y = [Maple Math] and its inverse y = [Maple Math] .

> 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]);

[Maple Plot]

2. The inverse function for [Maple Math] , - [Maple Math] /2 < x < [Maple Math] [Maple Math]

> 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]);

[Maple Plot]