ROV02_6.MWS

Chapter 2. Graphs of Composed Functions

Vladimir Rovenski, Haifa

> restart:

2.1 Graphs of Piecewise-Continuous Functions

2.1.1 Popular Piecewise-Constant Functions

The Heaviside (unit step) function

> plot(Heaviside(x), x=-2..2, ytickmarks=2, discont=true);

[Maple Plot]

Abbreviation for Heaviside function

> alias(H=Heaviside):

The derivative of the Heaviside function is the Dirac Delta function

> diff(H(x), x); plot(%, x=-2..2, axes=boxed);

[Maple Math]

[Maple Plot]

Graph of the function [Maple Math] = -1 if x < 0, 1 if x > 0, else 0 .

> plot(signum(x), x=-2..2, discont=true, ytickmarks=2);

[Maple Plot]

The graph of the integer part of x: [x] using the command floor(x)

(see also the command ceil(x) = floor(x)+1 ).

> plot(floor(x), x=-3..3, discont = false);

[Maple Plot]

If you would like to see how some MAPLE procedures and functions are programmed, use the following commands:

> interface(verboseproc=2): print(floor);

Return to the usual regime using the command

> interface(verboseproc=1);

A periodic impulse (or triangular wave) [Maple Math] -... for T=1

> plot(H(x)*signum(sin(Pi*x)), x=-1..6, scaling=constrained);

[Maple Plot]

Infinite stairs [Maple Math]

a)

> plot(H(x)*floor(x), x=-2..15);

[Maple Plot]

b)using the recursive procedure

> P2:=proc(x) option remember; if type(x, numeric) then if x<1 then 1 else P2(x-1)+1 fi fi end:

> plot(P2, -2..6.2, scaling=constrained);

[Maple Plot]

The graph of [Maple Math] (without the option discont=true) has similar view.

> plot(floor(x), x=-2..15);

[Maple Plot]

Plot steep stairs with the height of steps defined by the items of the following sum [Maple Math] = [Maple Math] .

> an:= n -> n/3: # insert your formula

> P_an:=proc(x) option remember; if type(x, numeric) then if x<0 then 0 else P_an(x-1)+an(floor(x)) fi: fi end:

> P_an(8); plot(P_an, -2..8.2, scaling=constrained);

[Maple Math]

[Maple Plot]

>

2.1.2 Discrete Statistical Functions

> restart:

1. Bernoulli distribution with the parameter p [Maple Math] (0,1).

> F1:=x -> if x<=0 then 0 elif x<=1 then 1-p else 1 fi;

[Maple Math]

> plot('subs(p=0.3, F1(x))', x=-1..2);

[Maple Plot]

2. Binomial distribution [Maple Math] (0 <= k <= n) with parameters [Maple Math] , [Maple Math] (0 < [Maple Math] < 1, [Maple Math] <= 1).

Define by recursion the distribution function

[Maple Math] if m < [Maple Math] , 1 if x > n, 0 if [Maple Math] .

> restart:

> F2:=proc(x) option remember; if type(x, numeric) then if x<=0 then 0 elif x<=n then F2(x-1)+binomial(n, ceil(x))*p^ceil(x)*(1-p)^(n-ceil(x)) else 1 fi fi end:

> plot(subs(p=0.25,n=10, F2), -1..n+1);

[Maple Plot]

>

Compare with the following method (plot both graphs):

> n:=10: p:=0.25: f2:=x -> sum(Dirac(x-k)*binomial(n,k)*p^k*(1-p)^(n-k), k=0..n);

[Maple Math]

> F2:=int(f2(x), x): plot([F2, 1], x=-1..n, discont=true);

[Maple Plot]

> q:=i -> plot([[i, 0], [i, subs(Dirac(0)=1, f2(i))]]): plots[display]([seq(q(i),i=-1..n)],axes=framed);

> [Maple Bitmap]

3. Poisson distribution [Maple Math] , (k= 0,1,2,...) with parameter [Maple Math] > 0.

Plot the distribution function [Maple Math] if m < [Maple Math] , 0 if [Maple Math] .

> F3:=proc(x) option remember; if type(x, numeric) then if x<=0 then 0 else F3(x-1)+lambda^ceil(x)*exp(-lambda)/ceil(x)! fi fi end;

[Maple Math]

> plot('subs(lambda=0.6, F3(x))', x=-2..6.2);

[Maple Plot]

>

2.1.3 Examples of Piecewise-Continuous Functions

> restart: readlib(piecewise):

1. Bernoulli distribution by the second method.

> F1:=x -> piecewise(x<=0, 0, x<=1, 1-p, 1);

[Maple Math]

> plot(subs(p=0.3, F1(x)), x=-1..2);

[Maple Plot]

>

> convert(F1(x), Heaviside); #convert(subs(p=0.3, F1(x)), Heaviside);

[Maple Math]

>

> assume(a<b): f:=piecewise(x<a, 0, x<=b, 1, 0);

[Maple Math]

The points of discontinuity of a function [Maple Math] of piecewise type

> readlib(discont): discont(f, x);

[Maple Math]

T he saw-shaped function .

> P:=proc(x) option remember; if type(x, numeric) then if x<0 then P(x+2) elif x<1 then 2*x elif x<2 then 0 else P(x-2) fi fi end:

> plot(P, -2..15, scaling=constrained);

[Maple Plot]

Obtain triangular waves from the previous function by reforming its fragment: x<2 then 4-2*x

> P:=proc(x) option remember; if type(x, numeric) then if x<0 then P(x+2) elif x<1 then 2*x elif x<2 then 4-2*x else P(x-2) fi fi end:

> plot(P, -2..15, scaling=constrained);

[Maple Plot]

or using one of the following formulas: y=arccos(cos(x)), y=arcsin(sin(x))

> plot(arccos(cos(x)), x=-2..25, scaling=constrained);

"Cut out" the function [Maple Math] (x [Maple Math] R) on the given segment [a,b]

> restart: piecewise: f:=x->x^2; # enter your function

[Maple Math]

> f_ab:=x->piecewise(x<a, 0, x<=b, f(x), 0); plot(subs({a=1, b=3}, f_ab(x)), x=0..5); # first method

[Maple Math]

[Maple Plot]

> f_ab:=x->f(x)*(Heaviside(x-a)-Heaviside(x-b)); plot(subs({a=1, b=3}, f_ab(x)), x=0..5); # second method

[Maple Math]

[Maple Plot]

2.2 Graphs of Piecewise-Differentiable Functions

Definition 1. A continuous function [Maple Math] given on the interval I = (a,b) is called piecewise-differentiable

if this interval can be broken onto a finite number of segments on each of which [Maple Math] belongs to the class [Maple Math] .

In other words, [Maple Math] ' piecewise-continuous.

2.2.1 The Functions max and min

The functions maximum and minimum can be converted into the type piecewise .

> g:=min(x^2,x+3): convert(g, piecewise); plot(g, x=-2..5);

[Maple Math]

[Maple Plot]

The graph of max ( min ) of several linear functions is a convex (or concave) polygon.

> n:=9: k:=seq(rand(-5..5)(), i=1..n); b:=seq(rand(1..30)(), i=1..n);

[Maple Math]

[Maple Math]

> fmax:=max(seq(k[i]*x+b[i], i=1..n)): fmin:=min(seq(k[i]*x+b[i], i=1..n)):

> Pmax:=plot(fmax(x), x=-10..10, thickness=3): Pmin:=plot(fmin(x), x=-10..10, thickness=3): PP:=plot([seq(k[i]*x+b[i], i=1..n)], x=-10..10):

> plots[display]([Pmax, Pmin, PP], axes=framed);

[Maple Plot]

>

2.2.2 Functions Containing the Operation abs

2. For a sequence of points [Maple Math] and weights [Maple Math] , where 1<=i<=n, find the minimum of the function [Maple Math] = [Maple Math] .

> a:=i -> 2+sqrt(i): b:=i->1: n:=6: # enter your data

> f:=x -> sum(b(i)*abs(x-a(i)), i=1..n); f(x);

[Maple Math]

[Maple Math]

> plot(f, a(1)-1..a(n)+1);

[Maple Plot]

The problem of machine tools with weight coefficients:

> f:=x -> 2*abs(x-(-3))+abs(x-(-1))+3*abs(x-2)+abs(x-6);

[Maple Math]

> f1:=convert(f(x), piecewise); plot(f1, x=-5..6);

[Maple Math]

[Maple Plot]

3. Symbolic integration of piecewise-differentiable functions in MAPLE .

> int(abs(2-abs(x)), x); plot(int(abs(2-abs(x)), x), x=-5..5);

[Maple Math]

[Maple Plot]

> f:=convert(abs(2-abs(x)), piecewise);

[Maple Math]

>

2.2.3 Piecewise-Differentiable Statistical Functions

The uniform distribution [Maple Math] = 1/{b-a} if x [Maple Math] [a,b], 0 if x \ [Maple Math] [a,b] on the segment [a,b]

has the continuous distribution [Maple Math] .

> readlib(piecewise):

> f:=x -> piecewise(x<=a, 0, x<=b, 1/(b-a), 0);

[Maple Math]

> plot(subs({a=1, b=3}, f(x)), x=-1..4);

[Maple Plot]

> F:=int(subs({a=1, b=3}, f(x)), x); plot(F, x=-1..4);

[Maple Math]

[Maple Plot]

The Simpson distribution on [a,b]. [Maple Math] = [Maple Math] - [Maple Math] if x [Maple Math] [a,b], 0 if x \ [Maple Math] [a,b].

> f:= x -> piecewise(x<a, 0, x<=b, 2/(b-a)-2/(b-a)^2*abs(a+b-2*x), x>b, 0);:

[Maple Math]

> plot(subs({a=1, b=3}, f(x)), x=-2..4);

[Maple Plot]

> F:=int(subs({a=1, b=3}, f(x)), x); plot(F, x=-1..4);

[Maple Math]

[Maple Plot]

The [Maple Math] - distribution [Maple Math] = 1/( [Maple Math] [Maple Math] ( [Maple Math] )) [Maple Math] [Maple Math] if x> 0, 0 if [Maple Math] with [Maple Math] degrees of freedom.

> f:=x->piecewise(x<=0, 0, 1/(2^(a/2)*GAMMA(a/2))*x^(a/2-1)*exp(-x/2));

[Maple Math]

> plot([seq(subs(a=i, f(x)), i=2..5)], x=-1..10, y=0..0.5);

[Maple Plot]

The exponential distribution [Maple Math] if [Maple Math] , 0 if [Maple Math] with parameter [Maple Math] >0.

> f:=x->piecewise(x<0, 0, lambda*exp(-lambda*x));

[Maple Math]

> plot([seq(subs(lambda=i/4, f(x)), i=1..4)], x=-1..4, y=0..1);

[Maple Plot]

The F Fisher distribution with ( [Maple Math] , [Maple Math] ) degrees of freedom

> f:= x -> piecewise(x<=0,0,(GAMMA((m1+m2)/2)*m1^(m1/2)*m2^(m2/2)*x^(m1/2-1))/(GAMMA(m1/2)*GAMMA(m2/2))* (m2+m1*x)^(-(m1+m2)/2));

[Maple Math]

> plot([seq(seq(subs(m1=10^i, m2=j, f(x)), i=0..1), j=1..2)], x=-1..3, y=0..0.6);

[Maple Plot]

2.2.4 Recursively Defined Functions

The graphs of recursively defined functions

1. f(x+1) = 2f(x) and [Maple Math] = x(1-x) (0< x < 1).

> f1:=proc(x) option remember; if type(x, numeric) then if x<0 then f1(x+1)/2 elif x<1 then x*(x-1) else 2*f1(x-1) fi: fi end:

> plot(f1, -2..3, scaling=constrained);

[Maple Plot]

2. [Maple Math] = [Maple Math] +sin(x) and [Maple Math] =0 ( [Maple Math] <= [Maple Math] ).

> f2:=proc(x) option remember; if type(x, numeric) then if x<0 then f2(x+Pi)+sin(x+Pi) elif x<Pi then 0 else f2(x-Pi)+sin(x-Pi) fi: fi end:

> plot(f2, -2*Pi..4*Pi, scaling=constrained);

[Maple Plot]

>

2.2.5 Functions That Are Defined Using limit

We can diversify the plotting of graphs of functions defined in terms of limits by applying the command animate .

1. [Maple Math] (x >= 0).

> restart: with(plots): animate(x^n/(1+x^n), x=0..3, n=1..50, thickness=2);

Warning, existing definition for changecoords has been overwritten

[Maple Plot]

Then we plot graphs of [Maple Math] together with graphs of their limits.

2. [Maple Math] , (x> -1)

> f:=(x-1)*arctan(x^n):

> p:=plot(limit(f, n=infinity), x=0..3, thickness=1):

> q:=animate(f, x=0..3, n=1..50, thickness=2):

> display([p, q], axes=framed);

[Maple Plot]

3. [Maple Math] (x \= 0),

> f:=(abs(x)^n-1)/(abs(x)^n+1):

> p:=plot(limit(f, n=infinity), x=-3..3, thickness=1):

> q:=animate(f, x=-3..3, n=1..50, thickness=2):

> display([p, q], axes=framed);

[Maple Plot]

4. [Maple Math] ,

> f:=x*arctan(n*cot(x)):

> p:=plot(limit(f, n=infinity), x=-3*Pi/2..3*Pi/2):

> q:=animate(f, x=-3*Pi/2..3*Pi/2, n=1..50, thickness=2):

> display([p, q], axes=framed);

[Maple Plot]

>