Appendix B: Software
277
aT=alpha*T;
y=[L;0];
A=[(exp(aT)-exp(-aT)-2*aT)/alpha , 1+aT-exp(aT);
(exp(-aT)+exp(aT)-2)/alpha , 1-exp(aT)]
x=A\y; C3=x(1); C4=x(2);
C1=2*alphaˆ2*C3-alphaˆ3*C4
C2=alphaˆ2*C4
% position
x1=@(t)C4-(C3/alpha)*exp(-alpha*t)-(C1/alphaˆ2)*t ...
-(1/(2*alphaˆ2))*(C2-C1/alpha)*exp(alpha*t);
% velocity
x2=@(t)C3*exp(-alpha*t)-C1/alphaˆ2 ...
-(1/(2*alpha))*(C2-C1/alpha)*exp(alpha*t);
subplot(2,1,1); plot(t,x1(t))
xlabel(’t [s]’); ylabel(’x=x_1 [m]’);
subplot(2,1,2); plot(t,x2(t))
xlabel(’t [s]’); ylabel(’v=x_2 [m/s]’);
The plots in Fig. 11.5 show the output of running the script two times; once with
α = 0.1 and once with α = 1.
B.9 Character Frequency in the King James Bible
The analysis to determine the entropy per character in the King James bible in
Sect. 12.1 is based on the following Unix script, written in bash. After defining
the input file, here pg10.txt, we translate all lower-case characters to upper case
with tr and then delete numbers and several special characters with the tr -d
command. Finally, we fold the input to a format that contains only one character per
line, which we then sort to have all equal characters following one another, before
removing the duplicates with the uniq -c command. The option -c writes the
number of occurrences of each character next to it, such that we obtain the table
shown in Sect. 12.1.
#!/bin/bash
input=pg10.txt
tr ’[:lower:]’ ’[:upper:]’ < $input \
| tr -d ’[0-9:\n;()?!-@$*#%/]’ > out.txt
fold -w1 < out.txt | sort | uniq -c > out2.txt
awk ’{print $1}’ < out2.txt > out3.txt
We point out that the end-of-line characters on UNIX and Windows systems differ
and running dos2unix pg10.txt might be required on a Unix system to fix that
problem.
277
aT=alpha*T;
y=[L;0];
A=[(exp(aT)-exp(-aT)-2*aT)/alpha , 1+aT-exp(aT);
(exp(-aT)+exp(aT)-2)/alpha , 1-exp(aT)]
x=A\y; C3=x(1); C4=x(2);
C1=2*alphaˆ2*C3-alphaˆ3*C4
C2=alphaˆ2*C4
% position
x1=@(t)C4-(C3/alpha)*exp(-alpha*t)-(C1/alphaˆ2)*t ...
-(1/(2*alphaˆ2))*(C2-C1/alpha)*exp(alpha*t);
% velocity
x2=@(t)C3*exp(-alpha*t)-C1/alphaˆ2 ...
-(1/(2*alpha))*(C2-C1/alpha)*exp(alpha*t);
subplot(2,1,1); plot(t,x1(t))
xlabel(’t [s]’); ylabel(’x=x_1 [m]’);
subplot(2,1,2); plot(t,x2(t))
xlabel(’t [s]’); ylabel(’v=x_2 [m/s]’);
The plots in Fig. 11.5 show the output of running the script two times; once with
α = 0.1 and once with α = 1.
B.9 Character Frequency in the King James Bible
The analysis to determine the entropy per character in the King James bible in
Sect. 12.1 is based on the following Unix script, written in bash. After defining
the input file, here pg10.txt, we translate all lower-case characters to upper case
with tr and then delete numbers and several special characters with the tr -d
command. Finally, we fold the input to a format that contains only one character per
line, which we then sort to have all equal characters following one another, before
removing the duplicates with the uniq -c command. The option -c writes the
number of occurrences of each character next to it, such that we obtain the table
shown in Sect. 12.1.
#!/bin/bash
input=pg10.txt
tr ’[:lower:]’ ’[:upper:]’ < $input \
| tr -d ’[0-9:\n;()?!-@$*#%/]’ > out.txt
fold -w1 < out.txt | sort | uniq -c > out2.txt
awk ’{print $1}’ < out2.txt > out3.txt
We point out that the end-of-line characters on UNIX and Windows systems differ
and running dos2unix pg10.txt might be required on a Unix system to fix that
problem.
