Figure 4.15:

The indicator (step) function f_1(w;x) and its smooth approximation, f(w;x).

Code for Figure 4.15

Text of the GNU GPL.

main.m


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
% make a tempered step function with three continuous derivatives
%
% Use piecewise cubic polynomial on [0,r] and [r, 2r]
% f is function, df is first derivative, d2f is second derivative,
% d3f is third derivative.
%
% jbr, 1/12/2013
%

L = 1; r = L/2;

npts = 51;
x = linspace(0, L, npts)';
f1 = (1/4)*(5*(x/r).^4 - 3*(x/r).^5);
z  = (2*r-x)/r;
f2 = -(1/4)*(5*z.^4 - 3*z.^5) + 1;
f = (x<=r).*f1 + (x >r).*f2;

pts = [0,1; 1,0];
lines = [-1,1; 0,1; 0,0; 2,0];
z = flipud(x);
figure()
plot(z,f, pts(:,1),pts(:,2), 'o', lines(:,1),lines(:,2))

% store numbers for plotting
smooth = [z, f];
save indicator.dat smooth pts lines