Approximations to Piecewise Continuous Functions Univ.-Prof. Dr.-Ing. habil. Josef BETTEN RWTH Aachen University Templergraben 55 D-52056 A a c h e n, Germany betten@mmw.rwth-aachen.de Abstract This worsheet is concerned with approximations to piecewise continuous functions. It has been illustrated that Maplesoft furnishes powerful tools in finding best approximations to several functions. Some examples are discussed in more detail. Keywords: step functions; HEAVISIDE functions; FOURIER approximation; L-two norm FOURIER Approximation restart: FOURIER_series(x a[0]/2+sum(a[]*cos(*x+b[]*sin(*x,=..infinity; FOURIER_series( x + 2 a 0 ( a cos( x + b sin( x = a[](/pi*int(f(x*cos(*x,x=0..2*pi; a a[0]simplify(subs(=0,%; 0 2 a 0 f( x cos( x 0 2 f( x b[](/pi*int(f(x*sin(*x,x=0..2*pi; 2 b f( x sin( x 0
Unit Step Function or HEAVISIDE Unit Function F(xpiecewise(x0 and x<pi,,xpi and x<2*pi,-,x2*pi,; 0 < x and x < F( x - < x and x < 2 2 < x plot(%,x=0..2.*pi,labels=[x,f],color=blac; Alternatively, the piecewise continuous function F(x can be represented as a HEAVISIDE function: alias(h=heaviside: HEAVISIDE[F]convert(F(x,H; HEAVISIDE F H( x 2 H ( x + 2 H( 2 + x plot(%,x=0..2.*pi,color=blac, title="heaviside unit step function"; A[0]value(subs(f(x=F(x,a[0]; A 0 0 A[]simplify(value(subs(f(x=F(x,a[]; A 2 sin( ( + cos( A[]subs(sin(*Pi=0,%; A 0 B[]simplify(value(subs(f(x=F(x,b[]; 2 cos( ( + cos( B B[]simplify(subs(cos(*Pi=(-^,%; 2( (- ( + + (- ( 2 B for i in [,3,5] do y(x,n=isum(b[]*sin(*x,=..i od; 2
4 sin( x y ( x, n = 4 sin( x 4 sin( 3 x y ( x, n = 3 + 3 4 sin( x 4 sin( 3 x 4 sin( 5 x y ( x, n = 5 + + 3 5 plot({y(x,n=,y(x,n=3,y(x,n=5},x=0..3.5*pi, labels=[x,y],color=blac, title="approximations with n = [, 3, 5]"; for i in [,3,99] do y(x,n=isum(b[]*sin(*x,=..i od: plot({y(x,n=,y(x,n=3,y(x,n=99},x=0..3.5*pi, labels=[x,y],color=blac, title="approximations with n = [, 3, 99]"; L_zwei[n]sqrt((/Pi*Int((F(x_-y(x,n^2,x=0..Pi; L_zwei n ( F( x_ y ( x, n 2 0 for i in [,3,5,99] do L_zwei[n=i] evalf(sqrt((/pi*int((f(x-y(x,n=i^2,x=0.05..0.95*pi,4 od; L_zwei n = 0.3658 L_zwei n = 3 0.2293 L_zwei n = 5 0.658 L_zwei n = 99 0.0289 Example: h(x 3
h(xpiecewise(x0 and x<pi,pi,xpi and x<2*pi,x-pi, x2*pi and x<3*pi,pi; h( x 0 < x and x < x < x and x < 2 2 < x and x < 3 plot(%,x=0..3*pi,color=blac,labels=[x,h]; alias(h=heaviside: HEAVISIDE[h]convert(h(x,H; HEAVISIDE h H( x 2 H ( x + x H ( x x H( 2 + x + 2 H( 2 + x H( 3 + x plot(%,x=0..3*pi,color=blac, title="heaviside Function for h(x"; A[0]value(subs(f(x=h(x,a[0]; 3 A 0 2 A[]simplify(value(subs(f(x=h(x,a[]: A[]subs({sin(*Pi=0,cos(*Pi=(-^,(cos(*Pi^2=},%; (- A 2 B[]simplify(value(subs(f(x=h(x,b[]: B[]subs({sin(*Pi=0,cos(*Pi=(-^,(cos(*Pi^2=},%; B (- y(x,na[0]/2+sum(a[]*cos(*x+b[]*sin(*x,=..n; n 3 y ( x, n + 4 ( (- cos( x (- sin( x = 2 4
for i in [,2,3] do y(x,n=ia[0]/2+sum(a[]*cos(*x+b[]*sin(*x,=..i od; 3 2 cos( x y ( x, n = + + sin( x 4 3 2 cos( x y ( x, n = 2 + + sin( x sin( 2 x 4 2 3 2 cos( x 2 cos( 3 x y ( x, n = 3 + + sin( x sin( 2 x + + sin( 3 x 4 2 9 3 alias(h=heaviside,co=color: p[]plot({y(x,n=,y(x,n=2,y(x,n=3},x=0..3*pi,co=blac: p[2]plot(.72*h(x-3*pi,x=0..3.0*pi,co=blac: p[3]plot(h(x,x=0..3*pi, title="approximations with n = [, 2, 3]" : plots[display]({seq(p[],=..3}; for i in [,2,50] do y(x,n=ia[0]/2+sum(a[]*cos(*x+b[]*sin(*x,=..i od: p[4]plot({y(x,n=,y(x,n=2,y(x,n=50},x=0..3*pi,co=blac: p[5]plot(.72*h(x-3*pi,x=0..3.0*pi,co=blac, title="approximations with n = [, 2, 50]": plots[display]({p[4],p[5]}; Smoothing of the FOURIER-Series y(x, n=3: g(,nsin(pi*/n/(pi*/n; # smoothing factor 5
sin N N g (, N G(x,n,NA[0]/2+ sum(g(appa,nu*(a[appa]*cos(appa*x+b[appa]*sin(appa*x, appa=..n; # smoothing function n 3 G ( x, n, N + 4 g ( κ, Ν ( A κ cos( κ x + B κ sin( κ x κ = g(,4subs(n=4,g(,n; # N n + 4 sin 4 g (, 4 G(x,n=3,N=4subs({n=3,Nu=4,appa=,g(appa,Nu=g(,4, A[appa]=A[],B[appa]=B[]},G(x,n,N; 3 4 sin ( (- cos( x ( 3 4 G ( x, n = 3, N = 4 + 4 2 = alias(h=heaviside,co=color: p[6]plot({y(x,n=3,g(x,n=3,n=4},x=0..3*pi,co=blac: p[7]plot(.72*h(x-3*pi,x=0..3.0*pi,co=blac: p[8]plot(h(x,x=0..3*pi, title="approximation with n = 3 and its Smoothing": plots[display](seq(p[],=6..8; - sin( x Smoothing of the FOURIER-Series y(x, n = 2: g(,3subs(n=3,g(,n; 3 sin 3 g (, 3 G(x,n=2,N=3evalf(A[0]/2+ sum(g(,3*(a[]*cos(*x+b[]*sin(*x,=..2,4; G ( x, n = 2, N = 3 2.356 + 0.5264 cos( x + 0.8268 sin( x 0.2067 sin( 2. x 6
alias(h=heaviside,co=color: p[9]plot({h(x,y(x,n=2,g(x,n=2,n=3},x=0..3*pi,co=blac, title="approximation with n = 2 and its Smoothing": plots[display]({p[7],p[9]}; The above Figures illustrate the good approximations to the given function h(x. Example: K(x K(xpiecewise(x-Pi and x<0,3,x0 and x</2,0, x/2 and x<pi,/x; 3 < x and x < 0 K( x 0 0 < x and x < 2 < x and x < x 2 plot(%,x=-pi..pi,color=blac,labels=[x,k]; alpha[0](/pi*int(f(x,x=-pi..pi; α 0 f( x alpha[](/pi*int(f(x*cos(*x,x=-pi..pi; α f( x cos( x beta[](/pi*int(f(x*sin(*x,x=-pi..pi; β f( x sin( x 7
Alpha[0]value(subs(f(x=K(x,alpha[0]; 3 + ln( 2 + ln( Α 0 Alpha[]simplify(value(subs(f(x=K(x,alpha[]; 3 sin( + Ci 2 Ci( Α A[]subs(sin(*Pi=0,%; Ci 2 Ci( A BETA[]simplify(value(subs(f(x=K(x,beta[]; 3 cos( 3 Si + 2 Si( BETA BETA[]subs(cos(*Pi=(-^,%; 3( - 3 Si + 2 Si( BETA y(x,nalpha[0]/2+ sum(alpha[]*cos(*x+beta[]*sin(*x,=..n: y(x,nsubs(sin(*pi=0,%; 3 + ln( 2 + ln( y ( x, n 2 n Ci 2 Ci( ( cos x 3( - 3 Si + 2 Si( sin ( x + + = y(x,subs(n=,y(x,n: Y(x,evalf(%,4; Y ( x,.792 + 0.07998 cos( x.477 sin( x y(x,3subs(n=3,y(x,n: Y(x,3evalf(%,4; Y ( x, 3.792 + 0.07998 cos( x.477 sin( x 0.46 cos( 2. x + 0.502 sin( 2. x 0.464 cos( 3. x 0.5249 sin( 3. x y(x,49subs(n=49,y(x,n: Y(x,49evalf(%: plot({y(x,,y(x,3,y(x,49},x=-pi..pi,co=blac, title="approximations with n = [, 3, 49]"; 8
L_two[n]sqrt((/2/Pi*Int((K(x_-Y(x,n^2,x=-Pi..Pi; L_two n 2 2 ( K( x_ Y ( x, n 2 for i in [,3,49] do L_two[n=i]evalf(sqrt((/2/Pi*int((K(x-Y(x,i^2,x=-3..3,4 od; L_two n = 0.6257 L_two n = 3 0.4876 L_two n = 49 0.06635 Example: M(x restart: M(xpiecewise(-Pi<x and x<0,, x0 and x</2,2, x/2 and x<pi,/x; < x and x < 0 M( x 2 0 < x and x < 2 < x and x < x 2 plot(%,x=-pi..pi,color=blac,labels=[x,m]; 9
a[0](/pi*int(f(x,x=-pi..pi; a 0 f( x a[](/pi*int(f(x*cos(*x,x=-pi..pi; a f( x cos( x b[](/pi*int(f(x*sin(*x,x=-pi..pi; b f( x sin( x A[0]value(subs(f(x=M(x,a[0]; + + ln( 2 + ln( A 0 A[]simplify(value(subs(f(x=M(x,a[]; sin( 2 sin + Ci 2 2 Ci( A A[]subs(sin(Pi*=0,%; 2 sin + Ci 2 2 Ci( A B[]simplify(value(subs(f(x=M(x,b[]; cos( + 2 cos Si + 2 2 Si( B B[]subs(cos(Pi*=(-^,%; (- + 2 cos Si + 2 2 Si( B for i in [,2,3,0] do y(x,n=ievalf(a[0]/2+ sum(a[]*cos(*x+b[]*sin(*x,=..i,4 od; y ( x, n = 0.955 + 0.3854 cos( x 0.260 sin( x y ( x, n = 2 0.955 + 0.3854 cos( x 0.260 sin( x + 0.532 cos( 2. x + 0.2964 sin( 2. x y ( x, n = 3 0.955 + 0.3854 cos( x 0.260 sin( x + 0.532 cos( 2. x + 0.2964 sin( 2. x + 0.06529 cos( 3. x + 0.09642 sin( 3. x y ( x, n = 0 0.955 + 0.3854 cos( x 0.260 sin( x + 0.532 cos( 2. x + 0.2964 sin( 2. x + 0.06529 cos( 3. x + 0.09642 sin( 3. x + 0.008250 cos( 4. x + 0.894 sin( 4. x 0.036 cos( 5. x + 0.05582 sin( 5. x 0.02397 cos( 6. x + 0.060 sin( 6. x 0.020 cos( 7. x + 0.0592 sin( 7. x 0.0576 cos( 8. x + 0.05968 sin( 8. x 0.00799 cos( 9. x 0.0007072 sin( 9. x 0.0008523 cos( 0. x + 0.0420 sin( 0. x 0
alias(h=heaviside,th=thicness,co=color: p[]plot({seq(y(x,n=i,i=..3},x=-pi..pi,co=blac: p[2]plot(m(x,x=-pi..pi,th=2,co=blac: p[3]plot(0.79*h(x+pi,x=-.00*pi..-0.999*pi,co=blac: p[4]plot(0.796*h(x-pi,x=0.999*pi...00*pi,co=blac, title="approximations with n = [, 2, 3]": plots[display]({seq(p[],=..4}; y(x,n=99evalf(a[0]/2+ sum(a[]*cos(*x+b[]*sin(*x,=..99,4: plot({m(x,y(x,n=99},x=-pi..pi,color=blac, title="m(x and y(x, n = 99"; L_two[n]sqrt((/2/Pi*Int((M(x_-y(x,n^2,x=-Pi..Pi; L_two n 2 2 ( M( x_ y ( x, n 2 for i in [,2,3,99] do L_two[n=i]evalf(sqrt((/2/Pi*int((M(x-y(x,n=i^2, x=-3..3,4 od; L_two n = 0.3048 L_two n = 2 0.963
L_two n = 3 0.770 L_two n = 99 0.02278 Smoothing of the FOURIER-Series y(x, n = 3: g(,nn*sin(*pi/n//pi; N sin N g (, N g(,4subs(n=4,%; 4 sin 4 g (, 4 G(x,n=3,N=4evalf(A[0]/2+ sum(g(,4*(a[]*cos(*x+b[]*sin(*x,=..3,4; G ( x, n = 3, N = 4 0.955 + 0.3468 cos( x 0.34 sin( x + 0.09752 cos( 2. x + 0.887 sin( 2. x + 0.0959 cos( 3. x + 0.02893 sin( 3. x plot({m(x,y(x,n=3,g(x,n=3,n=4},x=-pi..pi,color=blac, title="smoothing of the FOURIER-Series y(x, n = 3"; g(,subs(n=,g(,n; sin g (, G(x,n=0,N=evalf(A[0]/2+ sum(g(,*(a[]*cos(*x+b[]*sin(*x,=..0,4; G ( x, n = 0, N = 0.955 + 0.3800 cos( x 0.243 sin( x + 0.450 cos( 2. x + 0.2806 sin( 2. x + 0.05757 cos( 3. x + 0.08504 sin( 3. x + 0.006567 cos( 4. x 2
+ 0.508 sin( 4. x 0.00943 cos( 5. x + 0.03868 sin( 5. x 0.0384 cos( 6. x + 0.0620 sin( 6. x 0.009555 cos( 7. x + 0.00724 sin( 7. x 0.0052 cos( 8. x + 0.0973 sin( 8. x 0.0054 cos( 9. x 0.000487 sin( 9. x 0.00008406 cos( 0. x + 0.00444 sin( 0. x plot({m(x,y(x,n=0,g(x,n=0,n=},x=-pi..pi,color=blac, title="fourier-series y(x, n = 0 and its Smoothing"; Résumé In this worsheet it has been illustrated that Maplesoft furnishes powerful tools in finding best approximations to several piecewise continuous functions. 3