Chapter 9, continued
Download
Report
Transcript Chapter 9, continued
Numerical Integration Application:
Normal Distributions
Chapter 9
Numerical Integration
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Review: Numerical Integration
• When evaluating a definite integral, remember
that we are simply finding the area under the
curve between the lower and upper limits
• This can be done numerically by approximating
the area with a series of trapezoids
Engineering Computation: An Introduction Using MATLAB and Excel
Review: Trapezoid Area
• A trapezoidal area is formed:
Engineering Computation: An Introduction Using MATLAB and Excel
Other Numerical Integration Methods
• Higher-order functions allow fewer intervals to be
used for similar accuracy
• For example, Simpson’s Rule uses 2nd order
polynomial approximations to determine the area
• With the speed of modern computers, using these
more efficient algorithms is usually not necessary –
the trapezoid method with more intervals is
sufficient
Engineering Computation: An Introduction Using MATLAB and Excel
Application – Normal Distribution
• The standard deviation is a commonly-used
measure of the variability of a data population or
sample
• A higher standard deviation means that there is
greater variability
• If we assume that the population or standard is
distributed as a normal distribution, then we can
obtain a lot of useful information about
probabilities
Engineering Computation: An Introduction Using MATLAB and Excel
Normal Distribution
• Many numerical populations can be approximated
very closely by a normal distribution
• Examples:
– Human heights and weights
– Manufacturing tolerances
– Measurement errors in scientific experiments
• The population is characterized by its mean and
standard deviation
Engineering Computation: An Introduction Using MATLAB and Excel
Normal Distribution
• The probability density function of the normal
distribution can show a graphical view of how the
population is distributed
• The probability density function (pdf) is given by
this equation:
Engineering Computation: An Introduction Using MATLAB and Excel
Example
• Consider a population with a mean of 10 and a
standard deviation of 1. Here is the pdf:
Peak occurs at mean
value of x (10)
Frequency values
approach zero for xvalues far away from the
mean
Engineering Computation: An Introduction Using MATLAB and Excel
Effect of Standard Deviation
• What if the standard deviation is 1.5 instead of 1?
Here is the new pdf, compared with the original:
Note the “wider”
shape, as values are
more spread out
from the mean
when the standard
deviation is greater
σ = 1.0
σ = 1.5
Engineering Computation: An Introduction Using MATLAB and Excel
Notes About the Probability Density
Function
• The curve is symmetric about the mean
• Although the curve theoretically extends to infinity in
both directions, the function’s values approach zero
and can be ignored for x-values far away from the
mean
• The area under the curve is equal to one – this
corresponds to 100% of the population having xvalues greater than - and less than +
• The percentage of the population between other
limits can be computed by integrating the function
between those limits
Engineering Computation: An Introduction Using MATLAB and Excel
The Standard Normal Distribution
• The pdf can be standardized by introducing a new
variable Z, the standard normal random variable:
• The Z-value is simply the number of standard
deviations from the mean. Negative values
indicate that the data point is below the mean,
positive values indicate that the data point is
above the mean
Engineering Computation: An Introduction Using MATLAB and Excel
Examples
• For a population with a mean of 30 and a standard
deviation of 2, what is the Z-value for:
1. x = 27
Z = -1.5 (1.5 standard deviations below the mean)
2. x = 34
Z = +2.0 (2.0 standard deviations above the mean)
3. x = 30
Z=0
Engineering Computation: An Introduction Using MATLAB and Excel
Standard Normal Distribution
• Using the Z-values, we can write the equation for
the probability density function as:
• This form is especially useful in that the same
probability density graph applies to all normal
distributions (next slide)
Engineering Computation: An Introduction Using MATLAB and Excel
Standard Normal Distribution
Engineering Computation: An Introduction Using MATLAB and Excel
Integration of Standard Normal
Distribution Function
• As we have stated, the area under the curve from
- to + is equal to one
• Often, we want to find the area from - to a
specific value of Z
• For example, suppose we want to find the
percentage of values that are less than one
standard deviation above the mean
• This will be
Engineering Computation: An Introduction Using MATLAB and Excel
Integration of Standard Normal
Distribution Function
• This integral is known as the cumulative standard
normal distribution
• This integral does not have a closed-form solution,
and must be evaluated numerically
• There are tables of the results in most statistics
books
Engineering Computation: An Introduction Using MATLAB and Excel
Typical Table of Integral Values
Z-value to one
decimal place
Second decimal
place of Z-value
Engineering Computation: An Introduction Using MATLAB and Excel
Integral Value for Z = 1.00
• Integral = 0.841
• This means that 84.1% of all values will be less
than (mean + 1 standard deviation)
Engineering Computation: An Introduction Using MATLAB and Excel
Graphical Interpretation of Answer
Engineering Computation: An Introduction Using MATLAB and Excel
In-Class Exercises
• Consider a sample of concrete test specimens with
a mean compressive strength of 4.56 ksi and a
standard deviation of 0.482 ksi
• Using tables of the cumulative standard normal
distribution, find:
1. The percentage of tests with strength values less than
3.50 ksi
2. The percentage of tests with strength values greater
than 5.0 ksi
3. The strength value that 99.9% of tests will exceed
Engineering Computation: An Introduction Using MATLAB and Excel
1. Percentage of Values Less Than 3.5 ksi
• Z = (3.5 – 4.56)/0.482 = -2.199 (round to -2.20)
• From table:
• 0.0139, or 1.4% of values are less than 3.5 ksi.
Engineering Computation: An Introduction Using MATLAB and Excel
2. Percentage of Values Greater Than 5 ksi
• Z = (5.0 – 4.56)/0.482 = 0.913 (round to 0.91)
• From table:
• 0.8186 of the total values are less than 5 ksi, so
• 1 - 0.8186 = 0.1814, or 18.1% of values are
greater than 3.5 ksi.
Engineering Computation: An Introduction Using MATLAB and Excel
2. Percentage of Values Greater Than 5 ksi
• Note that Z = 0.913. Rather than rounding off, we
can get a slightly more accurate answer by linear
interpolation of the table values:
• Cumulative density =
Engineering Computation: An Introduction Using MATLAB and Excel
3. Strength Value That 99.9% of Tests Will
Exceed
• We want to find a value that 0.1% (0.001) of tests
are below
• From the table, find the Z-value corresponding to a
cumulative density of 0.001
• Z is approximately -3.10 (note that to 4 decimal
places, Z = -3.08 and Z = -3.09 have the same value
of 0.0010)
Engineering Computation: An Introduction Using MATLAB and Excel
3. Strength Value That 99.9% of Tests Will
Exceed
• Z = -3.10
• So the value that 99.9% of tests will exceed is 3.10
standard deviations below the mean:
• Therefore, 99.9% of tests will exceed a value of
3.07 ksi.
• If we set this value as the lower limit, then an
average of one of every 1000 batches of concrete
will not meet the specification
Engineering Computation: An Introduction Using MATLAB and Excel
Application with MATLAB
• Calculating the integral directly will eliminate the
need to use the tables
• Since we cannot begin our integration at -, what
value of lower limit should we use?
• How many intervals do we need to use to get
acceptable precision for our answers?
• We will experiment with different values for the
lower limit and number of intervals
Engineering Computation: An Introduction Using MATLAB and Excel
Function normdist
k = number of
function SUM = normdist(limit, k)
increments
lower = -limit;
upper = limit;
inc = (upper-lower)/k;
Making “limit” an
SUM = 0;
argument of the
x(1) = lower;
function allows us to
examine the effect of
y(1) = 1/sqrt(2*pi)*exp(-x(1)^2/2);
using different values
for i = 2:(k+1)
x(i) = x(i-1)+inc;
y(i) = 1/sqrt(2*pi)*exp(-x(i)^2/2);
SUM = SUM + .5*(y(i) + y(i-1))*(x(i) -x(i-1));
end
Engineering Computation: An Introduction Using MATLAB and Excel
Evaluation of Limits,
Number of Increments
>> format long
>> normdist(3,100)
ans =
0.997292229481189
>> normdist(3,1000)
ans =
0.997300124163755
>> normdist(6,1000)
ans =
0.999999998025951
>> normdist(6,10000)
ans =
0.999999998026819
>> normdist(6,100)
ans =
0.999999997940018
>> normdist(5,100)
ans =
0.999999414352763
Engineering Computation: An Introduction Using MATLAB and Excel
Conclusions
• Limit = 6 (6 standard deviations) gives accuracy to
eight decimal places
• Number of increments less important: similar
results for 100, 1000, and 10000 increments
• Use lower limit of -6 standard deviations, 1000
increments
Engineering Computation: An Introduction Using MATLAB and Excel
Modified Function normdist
function SUM = normdist(Z)
% Calculates the % of population with values less than Z
lower = -6;
upper = Z;
k = 1000;
inc = (upper-lower)/k;
SUM = 0;
x(1) = lower;
y(1) = 1/sqrt(2*pi)*exp(-x(1)^2/2);
for i = 2:(k+1)
x(i) = x(i-1)+inc;
y(i) = 1/sqrt(2*pi)*exp(-x(i)^2/2);
SUM = SUM + .5*(y(i) + y(i-1))*(x(i) -x(i-1));
end
Engineering Computation: An Introduction Using MATLAB and Excel
Check
>> normdist(0)
ans =
0.5000
Should be 0.50 since curve is symmetric
>> normdist(1)
ans =
0.8412
Checks with value from table
Engineering Computation: An Introduction Using MATLAB and Excel