Figure 4.18:

Smooth approximation to a unit step function, H(z-1).

Code for Figure 4.18

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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
% 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/13/2013
%

L = 2; 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;

df1 = (1/(4*r))*(20*(x/r).^3 - 15*(x/r).^4);
df2 = (1/(4*r))*(20*z.^3 - 15*z.^4);
df = (x<=r).*df1 + (x >r).*df2;

d2f1 = (1/(4*r^2))*(60*(x/r).^2 - 60*(x/r).^3);
d2f2 = -(1/(4*r^2))*(60*z.^2 - 60*z.^3);
d2f = (x<=r).*d2f1 + (x >r).*d2f2;

d3f1 = (1/(4*r^3))*(120*(x/r) - 180*(x/r).^2);
d3f2 = (1/(4*r^3))*(120*z - 180*z.^2);
d3f = (x<=r).*d3f1 + (x >r).*d3f2;

figure()
plot(x,f,'-o')
figure()
plot(x,df,'-o')
figure()
plot(x,d2f,'-o')
figure()
plot(x,d3f,'-o')

% store numbers for plotting

smooth = [x, f, df, d2f, d3f];

save indscaled.dat smooth