Matlab Programming For Engineers 5Th Edition Chapman Solutions Manual Full Chapter PDF
Matlab Programming For Engineers 5Th Edition Chapman Solutions Manual Full Chapter PDF
Matlab Programming For Engineers 5Th Edition Chapman Solutions Manual Full Chapter PDF
% Define variables:
% m -- Number of columns
% n -- Number of rows
% ran -- Output array
% Record of revisions:
% Date Programmer Description of change
% ==== ========== =====================
% 04/10/15 S. J. Chapman Original code
185
© 2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
% Define variables:
% ii -- Index variable
% ISEED -- Random number seed (global)
% jj -- Index variable
% m -- Number of columns
% msg -- Error message
% n -- Number of rows
% ran -- Output array
%
% Record of revisions:
% Date Programmer Description of change
% ==== ========== =====================
% 02/04/14 S. J. Chapman Original code
% 1. 04/05/15 S. J. Chapman Modified for 0 arguments
186
© 2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
7.2 Function randomn produces samples from a uniform random distribution on the range [low,high). If
low and high are not supplied, they default to 0 and 1 respectively. Note that function random0 is
placed in a folder named private below the folder containing randomn. Function random0 is only
accessible from function in the parent directory, not from other functions. A listing of the directory is
shown below:
C:\Data\book\matlab\5e\soln\Ex7.2>dir /s
Volume in drive C is SYSTEM
Volume Serial Number is 9084-C7B1
Directory of C:\Data\book\matlab\5e\soln\Ex7.2
Directory of C:\Data\book\matlab\5e\soln\Ex7.2\private
C:\Data\book\matlab\5e\soln\Ex7.2>
% Define variables:
% high -- Upper end of range
% low -- Lower end of range
% m -- Number of columns
% n -- Number of rows
% ran -- Output array
% Record of revisions:
% Date Programmer Description of change
187
© 2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
% ==== ========== =====================
% 04/10/15 S. J. Chapman Original code
The following function appears in a directory name private below the directory containing function
randomn:
% Define variables:
% ii -- Index variable
% ISEED -- Random number seed (global)
% jj -- Index variable
% m -- Number of columns
% msg -- Error message
% n -- Number of rows
% ran -- Output array
%
% Record of revisions:
% Date Programmer Description of change
% ==== ========== =====================
% 02/04/14 S. J. Chapman Original code
% 1. 04/05/15 S. J. Chapman Modified for 0 arguments
188
© 2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
% Declare global values
global ISEED % Seed for random number generator
When this function is used to generate a 4 x 4 array of random numbers between 3 and 4 the results are: :
>> randomn(4,4,3,4)
ans =
3.7858 3.0238 3.4879 3.5630
3.5319 3.0040 3.3435 3.0988
3.4300 3.5385 3.0946 3.6670
3.1507 3.1958 3.6362 3.9179
7.3 A single function hyperbolic that calculates the hyperbolic sine, cosine, and tangent functions is shown
below. Note that sinh, cosh, and tanh are subfunctions here.
% Define variables:
% fun -- Function to evaluate
189
© 2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
% x -- Input value
% result -- Result of calculation
% Record of revisions:
% Date Programmer Description of change
% ==== ========== =====================
% 04/10/15 S. J. Chapman Original code
% Calculate function
switch (fun)
case 'sinh',
result = sinh(x);
case 'cosh',
result = cosh(x);
case 'tanh',
result = tanh(x);
otherwise,
msg = ['Invalid input function: ' fun];
error(msg);
end
% Define variables:
% x -- input value
% result -- Result of calculation
% Record of revisions:
% Date Programmer Description of change
% ==== ========== =====================
% 04/10/15 S. J. Chapman Original code
% Calculate value.
result = (exp(x) - exp(-x)) / 2;
190
© 2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
% Define variables:
% x -- input value
% result -- Result of calculation
% Record of revisions:
% Date Programmer Description of change
% ==== ========== =====================
% 04/10/15 S. J. Chapman Original code
% Calculate value.
result = (exp(x) + exp(-x)) / 2;
% Define variables:
% x -- input value
% result -- Result of calculation
% Record of revisions:
% Date Programmer Description of change
% ==== ========== =====================
% 04/10/15 S. J. Chapman Original code
7.4 A program to create the three specified anonymous functions, and then to plot h ( f ( x ) , g ( x) ) over the
range −10 ≤ x ≤ 10 is shown below:
% Script file: test_anonymous.m
%
% Purpose:
% To create three anonymous functions, and then create a
% plot using them.
%
191
© 2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
% Record of revisions:
% Date Programmer Description of change
% ==== ========== =====================
% 04/10/15 S. J. Chapman Original code
%
% Define variables:
% f -- Function handle
% g -- Function handle
% h -- Function handle
% x -- Input data samples
7.5 The commands to plot the function f ( x) = 1/ x over the range 0.1 ≤ x ≤ 10.0 using function fplot
are shown below:
192
© 2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
xlabel('\bfx');
ylabel('\bff(x)');
grid on;
7.6 A script file to find the minimum of the function y ( x ) = x 4 − 3 x 2 + 2 x over the interval [0.5 1.5] using
function fminbnd is shown below:
193
© 2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
% Find the minimum of the function in the range
% 0.5 <= x <= 1.5.
[minloc,minval] = fminbnd(y,0.5,1.5);
disp(['The minimum is at location ' num2str(minloc)]);
>> test_fminbnd
The minimum is at location 0.99999
7.7 A script file to find the minimum of the function y ( x ) = x 4 − 3 x 2 + 2 x over the interval [0.5 1.5] using
function fminbnd is shown below:
>> test_fminbnd
The minimum in the range (-2,2) is at location -1.366
The minimum in the range (-1.5,0.5) is at location -1.366
195
© 2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
7.8 A script file to create a histogram of samples from a random normal distribution is shown below:
% Create histogram
hist(dist,21);
title('\bfHistogram of random values');
xlabel('\bfValue');
ylabel('\bfCount');
196
© 2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
When this program is executed, the results are:
>> test_randn
7.9 A Rose Plot is a circular histogram, where the angle data theta is divided into the specified number of
bins, and the count of values in each bin is accumulated. A script file to create a rose plot of samples from
a random normal distribution is shown below:
% Create histogram
rose(dist,21);
title('\bfRose Plot of random values');
197
© 2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
xlabel('\bfValue');
ylabel('\bfCount');
>> test_rose
7.10 A function that finds the maximum and minimum values of a user-supplied function over a specified
interval is given below:
198
© 2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
% xmin = location of smallest value found
% min_value = smallest value found
% xman = location of largest value found
% max_value = largest value found
% Define variables:
% dx -- Step size
% x -- Input values to evaluate fun at
% y -- Function output
% Record of revisions:
% Date Programmer Description of change
% ==== ========== =====================
% 04/12/15 S. J. Chapman Original code
% Evaluate function
y = feval(func,x);
% Display results
fprintf('The maximum value is %.4f at %.2f\n',max_value,xmax);
fprintf('The minimum value is %.4f at %.2f\n',min_value,xmin);
function y = fun(x)
%FUN Function to test extremes
% Record of revisions:
% Date Programmer Description of change
% ==== ========== =====================
% 07/21/11 S. J. Chapman Original code
When this program is run, the results are as shown below. The plot of the function below shows that the
program has correctly identified the extremes over the specified interval.
» test_extremes
The maximum value is 3.4163 at 0.62
The minimum value is -9.0000 at -1.00
200
© 2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
7.12 The function fzero locates a zero in a function either near to a user-specified point or within a user-
specified range. If a range is used, then the sign of the function must be different at the beginning and end
of the range. This suggests a strategy for solving this problem—we will search along the function between
0 and 2 π at regular steps, and if the function changes sign between two steps, we will call fzero to
home in on the location of the root.
Note that we can determine whether the function has changed sign between two points by multiplying them
together and seeing the resulting sign. If the sign of the product is negative, then the sign must have
changed between those two points.
% Create function
hndl = @ (x) cos(x).^2 - 0.25;
% Find zeros
zero_index = zero_index + 1;
zero_loc(zero_index) = fzero(hndl,[x(ii) x(ii+1)]);
% Display results
disp(['There is a zero at at ' num2str(zero_loc(zero_index))]);
end
end
% Now plot the function to demonstrate that the zeros are correct
figure(1);
plot(x,y,'b-','LineWidth',2);
201
© 2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
hold on;
plot(zero_loc,zeros(size(zero_loc)),'ro');
hold off;
title('\bfLocation of Function Zeros');
xlabel('\bfx');
ylabel('\bfy');
legend('Function','Zeros found by fzero');
grid on;
When this program is run, the results are as shown below. The plot of the function below shows that the
program has correctly identified the zeros over the specified interval.
>> find_zeros
There is a zero at at 1.0472
There is a zero at at 2.0944
There is a zero at at 4.1888
There is a zero at at 5.236
7.13 A program to evaluate and plot the function f ( x ) = tan 2 x + x − 2 between −2π and 2π in steps of
π /10 is shown below:
% Script file: eval_and_plot_fn.m
%
% Purpose:
% To find the zeros of the function f(x) = (cos (x))^2 - 0.25
% between 0 and 2*PI.
%
% Record of revisions:
202
© 2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
% Date Programmer Description of change
% ==== ========== =====================
% 04/12/15 S. J. Chapman Original code
%
% Define variables:
% hndl -- Function handle
% x -- Input values to examine
% y -- Value of the function at x
When this program is run, the results are as shown below. The plot is shown twice, once at full scale and
once with the maximum y axis value limited to 50, so that the details of the plot can be observed.
>> eval_and_plot_fn
203
© 2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
7.14 A program to find potential targets in a radar’s range/Doppler space is shown below. This program finds
potential targets by looking for points that are higher than all of the neighboring points.
% Calculate histogram
[nvals, amp_levels] = hist(amp(:), 31);
204
© 2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
[max_val, max_loc] = max(nvals);
% Tell user
fprintf('%7.1f %6.1f %6.1f %6.1f\n', ...
range(jj), velocity(ii), amp(ii,jj), snr);
end
end
end
>> find_radar_targets
Range Vel Amp SNR
-161.9 1.7 -100.9 4.1
-89.9 1.7 -98.8 6.1
125.9 1.7 -95.2 9.7
-143.9 2.5 -107.1 -2.2
-54.0 2.5 -96.8 8.1
-125.9 3.3 -106.3 -1.4
-89.9 4.1 -98.0 6.9
0.0 4.1 -72.3 32.6
125.9 4.1 -102.0 2.9
89.9 5.0 -101.9 3.0
143.9 5.0 -101.3 3.6
-125.9 5.8 -98.6 6.3
107.9 5.8 -104.7 0.2
-72.0 6.6 -96.5 8.4
0.0 6.6 -73.2 31.8
143.9 6.6 -101.3 3.6
-107.9 7.5 -100.7 4.2
-54.0 7.5 -97.7 7.2
107.9 7.5 -102.7 2.2
125.9 8.3 -102.3 2.6
0.0 9.1 -73.9 31.0
205
© 2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
72.0 9.1 -100.5 4.5
107.9 9.1 -102.2 2.8
-161.9 10.8 -99.3 5.6
0.0 10.8 -74.3 30.6
-72.0 11.6 -102.0 2.9
89.9 11.6 -99.5 5.4
0.0 12.4 -74.6 30.3
107.9 12.4 -102.4 2.5
143.9 12.4 -99.2 5.7
-125.9 13.3 -98.7 6.2
89.9 14.1 -106.7 -1.8
-72.0 14.9 -99.7 5.2
0.0 14.9 -74.9 30.0
-125.9 15.8 -97.9 7.0
-89.9 15.8 -98.0 6.9
143.9 15.8 -101.8 3.1
-143.9 17.4 -99.2 5.7
125.9 17.4 -97.4 7.5
143.9 18.3 -99.3 5.7
107.9 19.1 -102.9 2.0
-125.9 19.9 -101.3 3.6
0.0 19.9 -75.2 29.7
-72.0 20.8 -100.5 4.4
125.9 20.8 -95.7 9.2
-54.0 21.6 -99.8 5.2
-161.9 22.4 -99.9 5.1
-125.9 22.4 -103.1 1.8
0.0 22.4 -75.4 29.5
-107.9 23.2 -103.2 1.7
107.9 23.2 -103.8 1.1
143.9 23.2 -97.7 7.2
-125.9 24.1 -102.5 2.4
0.0 24.1 -75.4 29.5
-72.0 24.9 -103.0 1.9
89.9 24.9 -111.1 -6.2
-161.9 25.7 -99.1 5.8
-107.9 25.7 -96.7 8.3
-54.0 25.7 -97.7 7.2
0.0 25.7 -75.7 29.2
143.9 25.7 -96.5 8.5
107.9 26.6 -99.8 5.1
-161.9 28.2 -98.4 6.5
-125.9 28.2 -100.1 4.8
-72.0 28.2 -105.1 -0.1
0.0 28.2 -75.5 29.4
72.0 28.2 -95.9 9.0
-89.9 29.0 -104.4 0.5
107.9 29.0 -102.0 2.9
-125.9 29.9 -101.4 3.5
0.0 29.9 -75.1 29.8
-72.0 30.7 -96.7 8.2
-143.9 31.5 -100.6 4.4
0.0 31.5 -75.0 29.9
206
© 2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
-125.9 32.4 -102.7 2.2
125.9 32.4 -103.4 1.6
-143.9 33.2 -102.0 3.0
-107.9 34.0 -105.1 -0.2
-72.0 34.0 -101.7 3.3
89.9 34.0 -103.3 1.6
-125.9 34.9 -103.8 1.1
0.0 34.9 -74.8 30.1
125.9 34.9 -100.0 4.9
107.9 35.7 -98.0 6.9
-161.9 36.5 -99.5 5.4
-89.9 36.5 -103.8 1.2
143.9 37.4 -104.3 0.6
-143.9 38.2 -103.7 1.2
-107.9 38.2 -102.0 2.9
-72.0 38.2 -102.4 2.5
0.0 38.2 -74.1 30.8
-161.9 39.0 -98.7 6.2
-125.9 39.8 -103.1 1.8
-54.0 39.8 -98.2 6.7
125.9 40.7 -100.4 4.6
-125.9 42.3 -101.3 3.7
-89.9 42.3 -96.7 8.3
143.9 42.3 -98.2 6.8
107.9 43.2 -103.2 1.8
143.9 44.0 -98.6 6.4
-125.9 44.8 -95.8 9.1
125.9 45.6 -97.5 7.5
-107.9 46.5 -96.4 8.5
-72.0 46.5 -100.9 4.1
-54.0 47.3 -97.4 7.5
107.9 47.3 -102.8 2.1
-143.9 48.1 -100.1 4.8
-107.9 48.1 -99.2 5.7
-161.9 49.0 -98.6 6.3
-125.9 49.0 -98.5 6.4
125.9 49.0 -100.0 4.9
18.0 49.8 -65.4 39.5
-161.9 52.3 -53.5 51.4
-89.9 52.3 -51.7 53.2
18.0 52.3 -10.0 94.9
107.9 52.3 -50.8 54.1
-143.9 55.6 -98.9 6.0
-72.0 56.4 -105.0 -0.0
-89.9 57.3 -98.4 6.5
107.9 57.3 -99.3 5.6
143.9 57.3 -102.7 2.3
-125.9 58.1 -97.9 7.0
89.9 58.1 -104.3 0.6
125.9 58.9 -101.7 3.2
-161.9 59.8 -100.6 4.3
89.9 60.6 -99.8 5.1
143.9 60.6 -100.5 4.4
207
© 2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
-125.9 61.4 -98.6 6.3
-161.9 62.3 -100.1 4.8
89.9 62.3 -102.6 2.4
143.9 62.3 -100.2 4.8
-89.9 63.1 -101.5 3.4
107.9 63.1 -100.8 4.1
-161.9 63.9 -100.0 4.9
-125.9 63.9 -102.3 2.6
0.0 63.9 -62.6 42.4
89.9 64.7 -97.1 7.8
125.9 64.7 -102.8 2.1
0.0 67.2 -21.0 83.9
107.9 69.7 -99.0 6.0
-143.9 70.5 -100.2 4.7
125.9 70.5 -98.9 6.0
-125.9 71.4 -99.2 5.7
-72.0 71.4 -110.0 -5.1
0.0 71.4 -62.5 42.4
89.9 71.4 -101.5 3.4
-107.9 72.2 -104.7 0.2
143.9 72.2 -105.2 -0.3
-161.9 73.0 -101.3 3.7
-89.9 73.0 -102.9 2.0
125.9 73.0 -97.3 7.6
-125.9 73.9 -101.1 3.8
-72.0 73.9 -101.3 3.7
-161.9 74.7 -102.1 2.8
-107.9 74.7 -100.0 4.9
-143.9 75.5 -102.3 2.6
107.9 75.5 -100.5 4.4
-72.0 76.4 -100.3 4.6
-161.9 77.2 -103.7 1.2
-107.9 77.2 -100.7 4.3
125.9 77.2 -103.8 1.1
-125.9 78.0 -102.0 3.0
143.9 78.0 -103.3 1.6
89.9 78.8 -102.7 2.2
-143.9 79.7 -98.0 6.9
-89.9 79.7 -100.4 4.5
125.9 79.7 -96.3 8.6
-107.9 80.5 -100.1 4.8
-54.0 80.5 -102.5 2.4
-125.9 82.2 -98.6 6.3
-89.9 82.2 -99.2 5.8
107.9 82.2 -100.3 4.6
143.9 82.2 -99.4 5.5
Which target has the highest signal to noise ratio? What is the relative range and velocity of that target?
208
© 2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
7.15 A function to calculate the derivative of a sampled function is shown below:
% Define variables:
% dx -- Step size
% x -- Input values to evaluate fun at
% y -- Function output
% Record of revisions:
% Date Programmer Description of change
% ==== ========== =====================
% 04/12/15 S. J. Chapman Original code
% Calculate sin(x)
dx = 0.05;
x = 0:dx:99*dx;
sinx = sin(x);
% Calculate cos(x)
cosx = cos(x);
210
© 2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
The resulting plot is shown below. The derivative of sin(x) as calculated by the function is indeed very
close to cos(x).
7.16 A program that explores the effect of noise on a derivative is shown below:
% Calculate sin(x)
dx = 0.05;
x = 0:dx:99*dx;
sinx = sin(x);
211
© 2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
% Calculate sin(x) plus noise
noise = 0.04 * random0(1,length(sinx)) - 0.02;
sinxn = sinx + noise;
212
© 2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
The resulting plot is shown below. The noise in the input signal is greatly amplified by the process of
taking the derivative.
7.17 A program that explores the effect of noise on a derivative is shown below:
% Find roots
root_index = root_index + 1;
root_loc(root_index) = fzero(f,[x(ii) x(ii+1)]);
% Display results
disp(['There is a root at at ' num2str(root_loc(root_index))]);
end
end
% Now plot the function to demonstrate that the roots are correct
figure(1);
plot(x,y,'b-','LineWidth',2);
hold on;
plot(root_loc,zeros(size(root_loc)),'ro');
hold off;
title('\bfLocation of Function roots');
xlabel('\bfx');
ylabel('\bfy');
legend('Function','roots found by froot');
grid on;
>> find_roots
There is a root at at 4.6052
214
© 2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
The resulting plot is shown below.
% Define variables:
% n -- Non-negative integer input
% result -- Result of calculation
%
% Record of revisions:
% Date Programmer Description of change
% ==== ========== =====================
% 07/07/14 S. J. Chapman Original code
% 1. 04/13/15 S. J. Chapman CHeck for invalid input
>> fact(5)
ans =
120
>> fact(-4)
??? Error using ==> fact at 22
n must be a non-negative integer
>> fact(5.5)
??? Error using ==> fact at 22
n must be a non-negative integer
7.19 A function to calculate the nth Fibonacci number recursively is shown below.
function fn = fibonacci(n)
%FIBONACCI evaluates the nth Fibonacci number
% Function FIBONACCI evaluates the nth Fibonacci number
% recursively, where n is >= 0.
%
% Define variables:
% fn -- Fibonacci number
% n -- The item in the sequence to calculate
%
% Record of revisions:
% Date Programmer Description of change
% ==== ========== =====================
% 04/13/15 S. J. Chapman Original code
When this program is executed, the results are as shown below. Note that the error checks are working
properly, and the main calculations are also correct.
>> fibonacci(-1)
??? Error using ==> fibonacci at 21
n must be a non-negative integer
>> fibonacci(1)
ans =
1
>> fibonacci(5)
ans =
5
>> fibonacci(10)
ans =
55
7.20 A function that calculates the probability that two or more people from a group of n will have the same
birthday is shown below. This function calculates the probability by taking 100,000 random samples of n
people, and seeing if any two or more have the same birthday. In general, the resulting probabilities should
be accurate to within 1%. (Note: If you have a slow computer, you can reduce the number of trials that the
function is performing to improve execution time.)
% Define variables:
% birthdays -- Array of birthdays
% ii -- Loop index
% jj -- Loop index
% n_matches -- Number of matches that have occurred
% n_trials -- The number of trials to perform
%
% Record of revisions:
% Date Programmer Description of change
% ==== ========== =====================
% 04/13/15 S. J. Chapman Original code
A test program to determine the probability for groups of 2-40 people is shown below:
% Plot probabilities
plot(2:40,prob(2:40),'b-','LineWidth',2);
title('\bfProbability of 2 or more people with same birthday');
xlabel('\bfNumber of people in group');
ylabel('\bfProbability');
grid on;
>> test_birthday
n prob
= ====
2 0.0032
3 0.0082
4 0.0160
5 0.0275
6 0.0410
7 0.0569
8 0.0739
9 0.0937
10 0.1152
11 0.1418
12 0.1666
13 0.1975
14 0.2252
15 0.2527
16 0.2856
17 0.3180
18 0.3482
19 0.3811
20 0.4104
21 0.4462
22 0.4784
23 0.5115
24 0.5377
25 0.5703
26 0.5969
27 0.6267
28 0.6585
29 0.6807
30 0.7066
31 0.7292
219
© 2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
32 0.7524
33 0.7730
34 0.7948
35 0.8148
36 0.8309
37 0.8487
38 0.8630
39 0.8777
40 0.8898
7.21 A program to calculate the false alarm rate as a function of the threshold setting above the mean noise level
is shown below. This program generates 10,000,000 Rayleigh-distributed noise samples2, and determines
the fraction of those samples which exceed each of 9 threshold levels. (Caution: The ten million-sample
array in this program may take a long time to execute on a memory-limited computer. If necessary, you
can cut down the sample size. However at least 100,000 (105) samples will be necessary to approximate a
false alarm rate of 10-4.)
When this program is executed, the results are as shown below. To get a false alarm rate below 10-4, we
would need a threshold of 11 dB.
>> calc_cfar
The false alarm rate versus threshold level is:
Threshold = 5.0 dB Pfa = 8.42700e-002
Threshold = 6.0 dB Pfa = 4.45740e-002
Threshold = 7.0 dB Pfa = 2.00360e-002
Threshold = 8.0 dB Pfa = 7.27600e-003
Threshold = 9.0 dB Pfa = 2.01500e-003
Threshold = 10.0 dB Pfa = 4.27000e-004
Threshold = 11.0 dB Pfa = 5.90000e-005
Threshold = 12.0 dB Pfa = 7.00000e-006
Threshold = 13.0 dB Pfa = 1.00000e-006
221
© 2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
7.22 A function gen_func that generates functions to evaluate polynomials of the form f ( x ) = ax 2 + bx + c ,
where a, b, and c are specified by the user, is shown below. This function creates and returns a handle to a
nested function eval_func, which evaluates the polynomial function for a given x and the values of a,
b, and c specified when the function handle was created.
% Define variables:
% a -- Coefficient of x^2
% b -- Coefficient of x
% c -- Constant coefficient
% hndl -- Handle to function "eval_func"
% msg -- Error message
%
% Record of revisions:
% Date Programmer Description of change
% ==== ========== =====================
% 04/20/15 S. J. Chapman Original code
A function to plot a function, specified by a function handle, between specified limits is shown below:
% Define variables:
% hndl -- Handle to function "eval_func"
% msg -- Error message
% str -- Title string
% x -- X values to plot
222
© 2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
% x1 -- Starting value to plot
% x2 -- Ending value to plot
% y -- Y values to plot
%
% Record of revisions:
% Date Programmer Description of change
% ==== ========== =====================
% 04/20/15 S. J. Chapman Original code
224
© 2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
7.23 To solve this problem, we must first express the differential equation in the form where the derivative of
vout ( t ) is equal to a function. This is Equation (7.15) from the problem statement:
dvout 1 1
=− vout ( t ) + vin ( t ) (7.15)
dt RC RC
We will use function ode45 to solve for the solution to this differential equation. The input voltage as a
function of time is calculated in the following function:
% Define variables:
% t -- Time
% result -- Input voltage
%
% Record of revisions:
% Date Programmer Description of change
% ==== ========== =====================
% 04/20/15 S. J. Chapman Original code
% Calculate derivative
if t >= 0
else
% Before time 0
result = 0;
end
% Define variables:
% t -- Time (in days)
% y -- Vector of states (voltage)
%
% Record of revisions:
% Date Programmer Description of change
% ==== ========== =====================
% 04/20/15 S. J. Chapman Original code
% Calculate derivative
yprime = lambda * vin(t) - lambda * y;
227
© 2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
7.24 To solve this problem, we must first express the differential equation in the form where the derivative of
v( t ) is equal to a function. This equation is
dv 1
=− v ( t ) + vin ( t )
dt RC
% Define variables:
% t -- Time
% result -- Input voltage
%
% Record of revisions:
% Date Programmer Description of change
% ==== ========== =====================
% 04/20/15 S. J. Chapman Original code
% Calculate derivative
if (t >= 0) & (t <= 5)
result = t;
else
result = 0;
end
229
© 2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
Another random document with
no related content on Scribd:
escape, he took the pet from the basket, and placed him in Lady
Jane’s arms.
“See here,” he said, “I’ve sewed this band of leather around his
leg, and you can fasten a strong string to it. If your mama allows you
to have him, you can always tie him to something when you go out,
and leave him alone, and he will be there quite safe when you come
back.”
“I should never leave him alone. I should keep him with me
always,” said the child.
“But, if you should lose him,” continued the boy, spreading one of
the pretty wings over Lady Jane’s plump little arm, “I’ll tell you how
you can always know him. He’s marked. It’s as good as a brand. See
those three black crosses on his wing feathers. As he grows larger
they will grow too, and no matter how long a time should pass
without your seeing him, you’d always know him by these three little
crosses.”
“If mama says I can have him, I can take him with me, can’t I?”
“Certainly, this basket is very light. You can carry it yourself.”
“You know,” she whispered, glancing at her mother, who had
leaned her head on the back of the seat in front of her, and appeared
to be sleeping, “I want to see Carlo and kitty, and the ranch, and all
the lambs; but I mustn’t let mama know, because it’ll make her cry.”
“You’re a good little girl to think of your mother,” said the boy, who
was anxious to cultivate her confidence, but too well-bred to question
her.
“She has no one now but me to love her,” she continued, lowering
her voice. “They took papa from us, and carried him away, and
mama says he’ll never come back. He’s not gone to San Antonio,
he’s gone to heaven; and we can’t go there now. We’re going to New
York; but I’d rather go to heaven where papa is, only mama says
there are no trains or ships to take us there, now, but by-and-by
we’re going if we’re very good.”
The boy listened to her innocent prattle with a sad smile, glancing
uneasily now and then at the mother, fearful lest the plaintive little
voice might reach her ear; but she seemed to be sleeping, sleeping
uneasily, and with that hot flush still burning on her cheeks.
“Have you ever been in New York?” he asked, looking tenderly at
the little head nestled against his arm. She had taken off her hat, and
was very comfortably curled up on the seat with Tony in her lap. The
bird also seemed perfectly satisfied with his position.
“Oh, no; I’ve never been anywhere only on the ranch. That’s
where Carlo, and kitty, and the lambs were, and my pony, Sunflower;
he was named Sunflower, because he was yellow. I used to ride on
him, and papa lifted me on, and took me off; and Sunflower was so
gentle. Dear papa—I—loved him best of all and now he’s gone
away, and I can’t see him again.”
Here the rosy little face was buried in Tony’s feathers, and
something like a sob made the listener’s heart ache.
“Come, come,” he said softly, “you mustn’t cry, or I shall think you
don’t care for the blue heron.”
In a moment, her little head was raised, and a smile shone through
her tears. “Oh, I do, I do. And if I can have him I won’t cry for the
others.”
“I’m quite sure your mama will consent. Now, let me tell you about
my home. I live in New Orleans, and I have lots of pets,” and the boy
went on to describe so many delightful things that the child forgot her
grief in listening; and soon, very soon the weary little head drooped,
and she was sleeping with her rosy cheek pressed against his
shoulder, and Tony clasped close in her arms.
And so the long, hot afternoon passed away, and the train sped on
toward its destination, while the mother and the child slept, happily
unconscious of the strange fate that awaited them in that city, of
which the spires and walls were even now visible, bathed in the red
light of the evening sun.
CHAPTER II
TONY GOES WITH LADY JANE
A ND now that the end of the journey was so near, the drowsy
passengers began to bestir themselves. In order to look a little
more presentable, dusty faces and hands were hastily wiped, frowsy
heads were smoothed, tumbled hats and bonnets were arranged,
and even the fretful babies, pulled and coaxed into shape, looked
less miserable in their soiled garments, while their mothers wore an
expression of mingled relief and expectation.
Lady Jane did not open her eyes until her companion gently tried
to disengage Tony from her clasp in order to consign him to his
basket; then she looked up with a smile of surprise at her mother,
who was bending over her. “Why, mama,” she said brightly, “I’ve
been asleep, and I had such a lovely dream; I thought I was at the
ranch, and the blue heron was there too. Oh, I’m sorry it was only a
dream!”
“My dear, you must thank this kind young gentleman for his care of
you. We are near New Orleans now, and the bird must go to his
basket. Come, let me smooth your hair and put on your hat.”
“But, mama, am I to have Tony?”
The boy was tying the cover over the basket, and, at the child’s
question, he looked at the mother entreatingly. “It will amuse her,” he
said, “and it’ll be no trouble. May she have it?”
“I suppose I must consent; she has set her heart on it.”
The boy held out the little basket, and Lady Jane grasped it
rapturously.
“Oh, how good you are!” she cried. “I’ll never, never forget you,
and I’ll love Tony always.”
At that moment the young fellow, although he was smiling brightly,
was smothering a pang of regret, not at parting with the blue heron,
which he really prized, but because his heart had gone out to the
charming child, and she was about to leave him, without any
certainty of their ever meeting again. While this thought was vaguely
passing through his mind, the lady turned and said to him:
“I am going to Jackson Street, which I believe is uptown. Is there
not a nearer station for that part of the city, than the lower one?”
“Certainly, you can stop at Gretna; the train will be there in a few
minutes. You cross the river there, and the ferry-landing is at the foot
of Jackson Street, where you will find carriages and horse-cars to
take you where you wish to go, and you will save an hour.”
“I’m very glad of that; my friends are not expecting me, and I
should like to reach them before dark. Is it far to the ferry?”
“Only a few blocks; you’ll have no trouble finding it,” and he was
about to add, “Can’t I go with you and show you the way?” when the
conductor flung open the door and bawled, “Grate-na! Grate-na!
passengers for Grate-na!”
Before he could give expression to the request, the conductor had
seized the lady’s satchel, and was hurrying them toward the door.
When he reached the platform, the train had stopped, and they had
already stepped off. For a moment, he saw them standing on the
dusty road, the river and the setting sun behind them—the black-
robed, graceful figure of the woman, and the fair-haired child with her
violet eyes raised to his, while she clasped the little basket and
smiled.
He touched his hat and waved his hand in farewell; the mother
lifted her veil and sent him a sad good-by smile, and the child
pressed her rosy fingers to her lips, and gracefully and gravely threw
him a kiss. Then the train moved on; and the last he saw of them,
they were walking hand in hand toward the river.
As the boy went back to his seat, he was reproaching himself for
his neglect and stupidity. “Why didn’t I find out her name?—or the
name of the people to whom she was going?—or why didn’t I go with
her? It was too bad to leave her to cross alone, and she a stranger
and looking so ill. She seemed hardly able to walk and carry her bag.
I don’t see how I could have been so stupid. It wouldn’t have been
much out of my way, and, if I’d crossed with them, I should have
found out who they were. I didn’t want to seem too presuming, and
especially after I gave the child the heron; but I wish I’d gone with
them. Oh, she’s left something,” and in an instant he was reaching
under the seat lately occupied by the object of his solicitude.
“It’s a book, ‘Daily Devotions,’ bound in russia, silver clasp,
monogram ‘J. C.,’” he said, as he opened it; “and here’s a name.”
On the fly-leaf was written
Jane Chetwynd.
From Papa,
New York, Christmas, 18—.
“‘Jane Chetwynd,’ that must be the mother. It can’t be the child,
because the date is ten years ago. ‘New York.’ They’re from the
North then; I thought they were. Hello! here’s a photograph.”
It was a group, a family group—the father, the mother, and the
child; the father’s a bright, handsome, almost boyish face, the
mother’s not pale and tear-stained, but fresh and winsome, with
smiling lips and merry eyes, and the child, the little “Lady Jane,”
clinging to her father’s neck, two years younger, perhaps, but the
same lovely, golden-haired child.
The boy’s heart bounded with pleasure as he looked at the sweet
little face that had such a fascination for him.
“I wish I could keep it,” he thought, “but it’s not mine, and I must try
to return to it the owner. Poor woman! she will be miserable when
she misses it. I’ll advertise it to-morrow, and through it I’m likely to
find out all about them.”
Next morning some of the readers of the principal New Orleans
journals noticed an odd little advertisement among the personals:
Found, “Daily Devotions”; bound in red russia-leather, silver clasp,
with monogram, “J. C.” Address,
Blue Heron, P. O. Box 1121.
T HE next morning, Madame Jozain sent Raste across the river for
Dr. Debrot, for the sick woman still lay in a heavy stupor, her dull
eyes partly closed, her lips parched and dry, and the crimson flush of
fever burning on cheek and brow.
Before Raste went, Madame Jozain took the traveling bag into the
kitchen, and together they examined its contents. There were the
two baggage-checks, the tickets and money, besides the usual
articles of clothing, and odds and ends; but there was no letter, nor
card, nor name, except the monogram, J. C., on the silver fittings, to
assist in establishing the stranger’s identity.
“Hadn’t I better take these,” said Raste, slipping the baggage-
checks into his pocket, “and have her baggage sent over? When she
comes to, you can tell her that she and the young one needed
clothes, and you thought it was best to get them. You can make that
all right when she gets well,” and Raste smiled knowingly at
madame, whose face wore an expression of grave solicitude as she
said:
“Hurry, my son, and bring the doctor back with you. I’m so anxious
about the poor thing, and I dread to have the child wake and find her
mother no better.”
When Doctor Debrot entered Madame Jozain’s front room, his
head was not as clear as it ought to have been, and he did not
observe anything peculiar in the situation. He had known madame,
more or less, for a number of years, and he might be considered one
of the friends who thought well of her. Therefore, he never suspected
that the young woman lying there in a stupor was any other than the
relative from Texas madame represented her to be. And she was
very ill, of that there could be no doubt; so ill as to awaken all the
doctor’s long dormant professional ambition. There were new