Matlabchapter 7
Matlabchapter 7
Introduction to MATLAB
for Engineers, Third Edition
William J. Palm III
Chapter 7
Statistics, Probability,
and Interpolation
Copyright © 2010. The McGraw-Hill Companies, Inc. This work is only for
non-profit use by instructors in courses for which this textbook has been
adopted. Any other use without publisher’s consent is unlawful.
Breaking Strength of Thread
7-2
Histograms for 20 tests of thread strength. Figure 7.1–1, page
297
7-3
Absolute frequency histogram for 100 thread tests.
Figure 7.1–2. This was created by the program on page 298.
7-4
Use of the bar function for relative frequency histograms
(page 299).
7-5
Relative frequency histogram for 100 thread tests.
Figure 7.1–3
7-6
Use of the hist function for relative frequency
histograms.
tests = 100;
y =
[91*ones(1,13),92*ones(1,15),93*ones(1,22),...
94*ones(1,19),95*ones(1,17),96*ones(1,14)];
x = [91:96];
[z,x] = hist(y,x);bar(x,z/tests),...
ylabel(’Relative Frequency’),xlabel(’Thread
Strength (N)’),...
title(’Relative Frequency Histogram for 100
Tests’)
7-7
Histogram functions Table 7.1–1
Command Description
hist(y,x) Aggregates the data in the vector y into bins whose center
locations are specified by the vector x. The bin widths are
the distances between the centers.
[z,x] = hist(y) Same as hist(y) but returns two vectors z and x that
contain the frequency count and the bin locations.
[z,x] = hist(y,n) Same as hist(y,n) but returns two vectors z and x that
contain the frequency count and the bin locations.
[z,x] = hist(y,x) Same as hist(y,x) but returns two vectors z and x that
contain the frequency count and the bin locations. The
returned vector x is the same as the user-supplied
vector x.
7-8
The Data Statistics tool. Figure 7.1–4 on page 301
7-10
Scaled histogram of height data. Figure 7.2–1, page 302
7-11
Scaled histogram of height data for very many
measurements.
7-12
The basic shape of the normal distribution curve.
Figure 7.2–2, page 304
7-14
Probability interpretation of the μ ± σ limits.
7-15
Probability interpretation of the μ ± 2σ limits.
a−μ
erf b − μ
1
P(a ≤ x ≤ b) = − erf (7.2−3)
2 σ √2 σ √2
μu = μx + μy (7.2–4)
μυ = μx − μy (7.2–5)
7-18
Random number functions Table 7.3–1
Command Description
7-19
Table 7.3–1 (continued)
7-20
The following session shows how to obtain the same
sequence every time rand is called.
>>rand(’twister’,0)
>>rand
ans =
0.5488
>>rand
ans =
0.7152
>>rand(’twister’,0)
>>rand
ans =
0.5488
>>rand
ans =
7-21 0.7152
You need not start with the initial state in order to
generate the same sequence. To show this, continue
the above session as follows.
>>s = rand(’twister’);
>>rand(’twister’,s)
>>rand
ans =
0.6028
>>rand(’twister’,s)
>>rand
ans =
0.6028
7-22
The general formula for generating a uniformly distributed
random number y in the interval [a, b] is
y = (b − a) x + a (7.3–1)
7-23
If x is a random number with a mean of 0 and a
standard deviation of 1, use the following equation to
generate a new random number y having a standard
deviation of σ and a mean of μ.
y=σx+μ (7.3–2)
y = 3*randn(1,2000) + 5.
7-24
If y and x are linearly related, as
y = bx + c (7.3–3)
μy = bμx + c (7.3–4)
σy = |b|σx (7.3–5)
7-26
Scaled histogram of the angle θ. Figure 7.3–2, page 313
7-27
Applications of interpolation: A plot of temperature data
versus time. Figure 7.4–1, page 314
7-28
Temperature measurements at four locations. Figure 7.4–2,
page 316
More? See
pages 313-317.
7-29
Linear interpolation functions. Table 7.4–1, page 317
Command Description
7-30
Table 7.4–1 Continued
Z_int = interp2(x,y,z,x_int,y_int)
7-31
Cubic-spline interpolation: The following session produces
and plots a cubic-spline fit, using an increment of 0.01 in
the x values (pages 317-319).
>>x = [7,9,11,12];
>>y = [49,57,71,75];
>>x_int = 7:0.01:12;
>>y_int = spline(x,y,x_int);
>>plot(x,y,’o’,x,y,’--’,x_int,y_int),...
xlabel(’Time (hr)’),ylabel(’Temperature
(deg F)’,...
title(’Temperature Measurements at a
Single Location’),...
axis([7 12 45 80])
7-33
Polynomial interpolation functions. Table 7.4–2, page 320
Command
y_est = interp1(x,y,x_est,’spline’)
Description
7-34
Table 7.4–2 Continued
y_int = spline(x,y,x_int)
7-35
Table 7.4–2 Continued
y_int = pchip(x,y,x_int)
7-36
Table 7.4–2 Continued
7-37
The next slide illustrates interpolation using a cubic polynomial
and an eighth order polynomial (top graph). The cubic is not
satisfactory in this case, and the eighth order polynomial is not
suitable for interpolation over the interval 0 < x < 0.5.
The cubic spline does a better job in this case (bottom graph).
7-38
Figure 7.4-4 Top: Cubic and eighth order
polynomial interpolation. Bottom: Cubic spline
(page 321).
7-39
The next slide illustrates interpolation using a fifth order
polynomial and a cubic spline (top graph). The cubic spline is
better because the fifth order polynomial displays wide variations
between the data points.
The pchip polynomial does a better job than the cubic spline in
this case (bottom graph).
7-40
Figure 7.4-5 Top: Fifth order polynomial and cubic
spline interpolation. Bottom: pchip and cubic spline
interpolation. (page 323)
7-41