# # > restart; > #This worksheet is intended to give you some feeling of how to use > convolution to approximately compute derivatives. In the next command > replace sin(x) with the function of your choice. Use a function for > which maple can compute its symbolic derivatives. This is the function > we will study in the rest of the worksheet. > g := x-> sin(x); #Rplace sin(x) here with other functions. > g1 := D(g); > g2 := D(g1); > #Here we convolve g with a rectangular pulse of width h and plot the > results for several values of h. > f0 := (x,h)->(1/(2*h))*evalf(int(g(y),y=x-h..x+h)); > plot([g(x),f0(x,.025),f0(x,.1),f0(x,.5),f0(x,1)],x=-Pi..Pi); > #This command convolves g with the weak derivative of a tent function. > This gives an approximation to the derivative of g. We again plot the > convolution for several values of h along with g itself. > f1 := (x,h) -> > (1/(h^2))*(evalf(int(g(y),y=x..x+h))-evalf(int(g(y),y=x-h..x))); > plot([g1(x),f1(x,.1),f1(x,.25),f1(x,.5)],x=-Pi..Pi); > #We examine the graphs more carefully near to x=0. > plot([cos(x),f1(x,.1),f1(x,.25),f1(x,.5)],x=-0.2..0.2); > #Finally we convolve g with a weight which is the second derivative of > the function "w" shown in the next plot. This function is supported in > the interval [-2h,2h]. It has two weak derivatives. We first compute > and plot w and its first and second weak derivatives. > w := (x,h)->piecewise(-2*h<= x and x<-h, (x^2+4*h*x+4*h^2), -h<= x and > x w1 := (x,h)->piecewise(-2*h<= x and x<-h, 2*x+4*h, -h<= x and x -2*x, h w2 := (x,h)->piecewise(-2*h<= x and x<-h, 2, -h<= x and x and x<2*h, 2,0)/(4*h^3); > plot([w(x,.5),w1(x,.5),w2(x,.5)],x=-1..1);#Try this out with different > h values. > #Here we convolve g with D^2 w. > f2 := > (x,h)->(1/(2*h^3))*(evalf(int(g(y),y=x-2*h..x-h))+evalf(int(g(y),y=x+h > ..x+2*h))-evalf(int(g(y),y=x-h..x+h))); > #These plots show the second derivative of g along with several > approximations obtained by convolving with D^2 w. > plot([g2(x),f2(x,.1),f2(x,.25),f2(x,.5)],x=-Pi..Pi); > #We examine these plots more carefully near to Pi/2. > plot([g2(x),f2(x,.1),f2(x,.25),f2(x,.5)],x=Pi/2-.2..Pi/2+.2); >