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);
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);
Graph of the function = -1 if x < 0, 1 if x > 0, else 0 .
> plot(signum(x), x=-2..2, discont=true, ytickmarks=2);
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);
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) -... for T=1
> plot(H(x)*signum(sin(Pi*x)), x=-1..6, scaling=constrained);
Infinite stairs
a)
> plot(H(x)*floor(x), x=-2..15);
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);
The graph of (without the option discont=true) has similar view.
> plot(floor(x), x=-2..15);
Plot steep stairs with the height of steps defined by the items of the following sum = .
> 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);
>
2.1.2 Discrete Statistical Functions
> restart:
1. Bernoulli distribution with the parameter p (0,1).
> F1:=x -> if x<=0 then 0 elif x<=1 then 1-p else 1 fi;
> plot('subs(p=0.3, F1(x))', x=-1..2);
2. Binomial distribution (0 <= k <= n) with parameters , (0 < < 1, <= 1).
Define by recursion the distribution function
if m < , 1 if x > n, 0 if .
> 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);
>
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);
> F2:=int(f2(x), x): plot([F2, 1], x=-1..n, discont=true);
> q:=i -> plot([[i, 0], [i, subs(Dirac(0)=1, f2(i))]]): plots[display]([seq(q(i),i=-1..n)],axes=framed);
>
3. Poisson distribution , (k= 0,1,2,...) with parameter > 0.
Plot the distribution function if m < , 0 if .
> 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;
> plot('subs(lambda=0.6, F3(x))', x=-2..6.2);
>
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);
> plot(subs(p=0.3, F1(x)), x=-1..2);
>
> convert(F1(x), Heaviside); #convert(subs(p=0.3, F1(x)), Heaviside);
>
> assume(a<b): f:=piecewise(x<a, 0, x<=b, 1, 0);
The points of discontinuity of a function of piecewise type
> readlib(discont): discont(f, x);
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);
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);
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 (x R) on the given segment [a,b]
> restart: piecewise: f:=x->x^2; # enter your function
> 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
> 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
2.2 Graphs of Piecewise-Differentiable Functions
Definition 1. A continuous function 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 belongs to the class .
In other words, ' 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);
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);
> 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);
>
2.2.2 Functions Containing the Operation abs
2. For a sequence of points and weights , where 1<=i<=n, find the minimum of the function = .
> 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);
> plot(f, a(1)-1..a(n)+1);
The problem of machine tools with weight coefficients:
> f:=x -> 2*abs(x-(-3))+abs(x-(-1))+3*abs(x-2)+abs(x-6);
> f1:=convert(f(x), piecewise); plot(f1, x=-5..6);
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);
> f:=convert(abs(2-abs(x)), piecewise);
>
2.2.3 Piecewise-Differentiable Statistical Functions
The uniform distribution = 1/{b-a} if x [a,b], 0 if x \ [a,b] on the segment [a,b]
has the continuous distribution .
> readlib(piecewise):
> f:=x -> piecewise(x<=a, 0, x<=b, 1/(b-a), 0);
> plot(subs({a=1, b=3}, f(x)), x=-1..4);
> F:=int(subs({a=1, b=3}, f(x)), x); plot(F, x=-1..4);
The Simpson distribution on [a,b]. = - if x [a,b], 0 if x \ [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);:
> plot(subs({a=1, b=3}, f(x)), x=-2..4);
> F:=int(subs({a=1, b=3}, f(x)), x); plot(F, x=-1..4);
The - distribution = 1/( ( )) if x> 0, 0 if with degrees of freedom.
> f:=x->piecewise(x<=0, 0, 1/(2^(a/2)*GAMMA(a/2))*x^(a/2-1)*exp(-x/2));
> plot([seq(subs(a=i, f(x)), i=2..5)], x=-1..10, y=0..0.5);
The exponential distribution if , 0 if with parameter >0.
> f:=x->piecewise(x<0, 0, lambda*exp(-lambda*x));
> plot([seq(subs(lambda=i/4, f(x)), i=1..4)], x=-1..4, y=0..1);
The F Fisher distribution with ( , ) 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));
> plot([seq(seq(subs(m1=10^i, m2=j, f(x)), i=0..1), j=1..2)], x=-1..3, y=0..0.6);
2.2.4 Recursively Defined Functions
The graphs of recursively defined functions
1. f(x+1) = 2f(x) and = 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);
2. = +sin(x) and =0 ( <= ).
> 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);
>
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. (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
Then we plot graphs of together with graphs of their limits.
2. , (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);
3. (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);
4. ,
> 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);
>