CPET 190
description
Transcript of CPET 190
February 28, 2005February 28, 2005 Lecture 11 - By Paul LinLecture 11 - By Paul Lin 11
CPET 190 CPET 190
Problem Solving with MATLABProblem Solving with MATLAB
Lecture 11Lecture 11
http://www.ecet.ipfw.edu/~linhttp://www.ecet.ipfw.edu/~lin
February 28, 2005February 28, 2005 Lecture 11 - By Paul LinLecture 11 - By Paul Lin 22
Lecture 11: Solving Basic Lecture 11: Solving Basic Statistics ProblemsStatistics Problems
11-1 Introduction to Statistics 11-1 Introduction to Statistics
11-2 Statistical Analysis11-2 Statistical Analysis• Arithmetic MeanArithmetic Mean• VarianceVariance• Standard DeviationStandard Deviation
11-3 Empirical Linear Equation11-3 Empirical Linear Equation
February 28, 2005February 28, 2005 Lecture 11 - By Paul LinLecture 11 - By Paul Lin 33
11-1 Introduction to Statistics11-1 Introduction to Statistics
Origin of Statistics (18Origin of Statistics (18thth century) century)• Game of chance, and what is now Game of chance, and what is now
called political sciencescalled political sciences• Descriptive statistics: numerical Descriptive statistics: numerical
description of political units (cities, description of political units (cities, provinces, countries, etc); presentation provinces, countries, etc); presentation of data in tables and charts; of data in tables and charts; summarization of data by means of summarization of data by means of numerical descriptionnumerical description
Reference: Chapter 14 Statistics, Engineering Fundamentals and Problem Solving, Arvid Edie, et. al. McGrawHill, 1979
February 28, 2005February 28, 2005 Lecture 11 - By Paul LinLecture 11 - By Paul Lin 44
11-1 Introduction to Statistics11-1 Introduction to Statistics
Statistics InferenceStatistics Inference• Make generalization about collected data using Make generalization about collected data using
carefully controlled variables carefully controlled variables Applications of StatisticsApplications of Statistics
• Decision makingDecision making• Gaming industriesGaming industries• Comparison of the efficiency of production Comparison of the efficiency of production
processesprocesses• Quality ControlQuality Control
Measure of central tendency (mean or average)Measure of central tendency (mean or average) Measure of variation (standard deviation)Measure of variation (standard deviation) Normal curveNormal curve Linear regressionLinear regression
February 28, 2005February 28, 2005 Lecture 11 - By Paul LinLecture 11 - By Paul Lin 55
11-1 Introduction to Statistics11-1 Introduction to Statistics Basic Statistical AnalysisBasic Statistical Analysis
• A large set of measured data or numbersA large set of measured data or numbers• Average value (or arithmetic mean)Average value (or arithmetic mean)• Standard Deviation Standard Deviation • Study and summarize the results of the measured data, and Study and summarize the results of the measured data, and
moremore
Example 1: Student performance comparisonExample 1: Student performance comparison Two ECET students are enrolled in the CPET 190 and each Two ECET students are enrolled in the CPET 190 and each
completed five quizzes: qz1, qz2, qz3, qz4, and qz5. The grades are completed five quizzes: qz1, qz2, qz3, qz4, and qz5. The grades are in the array format:in the array format:• A = [82 61 88 78 80];A = [82 61 88 78 80];• B =[94 98 92 90 85];B =[94 98 92 90 85];
Student A has an average score of (82 + 61 + 88 + 78 + 90)/5 = 71.80Student A has an average score of (82 + 61 + 88 + 78 + 90)/5 = 71.80 Student B has an average score of (94 + 98 +92 + 90 + 85)/5 = 91.80Student B has an average score of (94 + 98 +92 + 90 + 85)/5 = 91.80 Statistical Inference: Student B Better Than Student A????Statistical Inference: Student B Better Than Student A????
February 28, 2005February 28, 2005 Lecture 11 - By Paul LinLecture 11 - By Paul Lin 66
11-1 Introduction to Statistics11-1 Introduction to Statistics
Example 1: Student performance comparison Example 1: Student performance comparison (continue)(continue)
Statistical Inference: Student B Better Than Statistical Inference: Student B Better Than Student A????Student A????
Two Possible Answers:Two Possible Answers:• Student B’s average grade 91.80 higher than Student B’s average grade 91.80 higher than
A’s average grade 71.80, so that student B is a A’s average grade 71.80, so that student B is a betterbetter student? Not quite true. student? Not quite true.
• Student B Student B may be bettermay be better than A. This could be a than A. This could be a more accurate answer.more accurate answer.
February 28, 2005February 28, 2005 Lecture 11 - By Paul LinLecture 11 - By Paul Lin 77
Example 1: The MATLAB SolutionExample 1: The MATLAB Solution% ex10_1.m% ex10_1.m% By M. Lin% By M. Lin% Student Performance % Student Performance
ComparisonComparisonformat bank % 2 digitsformat bank % 2 digitsA = [82 61 88 78 80];A = [82 61 88 78 80];B =[94 98 92 90 85];B =[94 98 92 90 85];A_total = 0;A_total = 0;B_total = 0;B_total = 0;for n = 1: length(A)for n = 1: length(A) A_total = A_total + A(n);A_total = A_total + A(n);endendA_avgA_avg = A_total/length(A) = A_total/length(A)%71.80%71.80for n = 1: length(B)for n = 1: length(B) B_total = B_total + B(n);B_total = B_total + B(n);endendB_avg B_avg = B_total/length(B)= B_total/length(B)% 91.80% 91.80
if A_avg > B_avg;if A_avg > B_avg; disp('Student A is better than disp('Student A is better than student B')student B') A_avgA_avgelseelse disp('Student B is better than disp('Student B is better than student A')student A') B_avgB_avgendendformat short % 4 digitsformat short % 4 digits
>> Student B is better than student A
B_avg = 91.80
February 28, 2005February 28, 2005 Lecture 11 - By Paul LinLecture 11 - By Paul Lin 88
11-2 Statistical Analysis11-2 Statistical Analysis
Statistical AnalysisStatistical Analysis• Data grouping and classifying dataData grouping and classifying data• Measures of tendency Measures of tendency
Arithmetic mean or average value.Arithmetic mean or average value.• Measures of variationMeasures of variation
VarianceVariance Standard Deviation Standard Deviation
• Predict or forecast the outcome of certain Predict or forecast the outcome of certain eventsevents
Linear regression (the simplest one)Linear regression (the simplest one)
February 28, 2005February 28, 2005 Lecture 11 - By Paul LinLecture 11 - By Paul Lin 99
11-2 Statistical Analysis11-2 Statistical Analysis
Arithmetic mean or average valueArithmetic mean or average value
Where N measurements are designated xWhere N measurements are designated x11 , x, x22 , .., ..
Or in the closed form asOr in the closed form as
N
xxxxMean n
...321
N
iixN
Mean1
1
February 28, 2005February 28, 2005 Lecture 11 - By Paul LinLecture 11 - By Paul Lin 1010
MEAN() - MATLAB Function for MEAN() - MATLAB Function for Calculating Average or Mean ValuesCalculating Average or Mean Values
MEAN Average or mean value.MEAN Average or mean value. For vectors, MEAN(X) is the mean value of the elements in X. For vectors, MEAN(X) is the mean value of the elements in X.
For matrices, MEAN(X) is a row vector containing the mean For matrices, MEAN(X) is a row vector containing the mean value of each column. For N-D arrays, MEAN(X) is the mean value of each column. For N-D arrays, MEAN(X) is the mean value of the elements along the first non-singleton dimension value of the elements along the first non-singleton dimension of X.of X.
Example 2:Example 2: If X = [0 1 2 3 4 5], then mean(X) = 2.5000 If X = [0 1 2 3 4 5], then mean(X) = 2.5000
>> X = [0 1 2 3 4 5]; >> X = [0 1 2 3 4 5]; >> mean(X)>> mean(X)ans = 2.5000ans = 2.5000 Verify the answer by hand:Verify the answer by hand:(0 + 1 + 2 + 3 + 4 + 5)/6 = 15/6 = 2.5.(0 + 1 + 2 + 3 + 4 + 5)/6 = 15/6 = 2.5.
February 28, 2005February 28, 2005 Lecture 11 - By Paul LinLecture 11 - By Paul Lin 1111
VarianceVariance The variance is a measure of how spread out a distribution is.The variance is a measure of how spread out a distribution is.
Where x is each measurement, Where x is each measurement, μμ is the mean, and N is the is the mean, and N is the number of measurementnumber of measurement
It is computed as the average squared deviation of each It is computed as the average squared deviation of each number from its mean.number from its mean.
Example 3:Example 3: we measure three resistors in a bin and read the we measure three resistors in a bin and read the resistances 1 ohm, 2 ohms, and 3 ohms, the mean is resistances 1 ohm, 2 ohms, and 3 ohms, the mean is (1+2+3)/3, or 2 ohms, and the variance is(1+2+3)/3, or 2 ohms, and the variance is
667.0
3
)23()22(21 2222
N
x
22 )(
February 28, 2005February 28, 2005 Lecture 11 - By Paul LinLecture 11 - By Paul Lin 1212
Standard DeviationStandard Deviation
A measure of the dispersion (or spread) of a set of data A measure of the dispersion (or spread) of a set of data from its mean. from its mean.
The more spread apart the data is, the higher the deviation. The more spread apart the data is, the higher the deviation. A statistic about how tightly all the various measurement are A statistic about how tightly all the various measurement are
clustered around the mean in a set of data. clustered around the mean in a set of data. When the examples are pretty tightly bunched together and When the examples are pretty tightly bunched together and
the bell-shaped curve is steep, the standard deviation is the bell-shaped curve is steep, the standard deviation is small. small.
When the examples are spread apart and the bell curve is When the examples are spread apart and the bell curve is relatively flat, that tells you have a relatively large standard relatively flat, that tells you have a relatively large standard deviation.deviation.
)1(
)(1 1
22
NN
xxNstd
N
i
N
iii
February 28, 2005February 28, 2005 Lecture 11 - By Paul LinLecture 11 - By Paul Lin 1313
MATLAB Function for Standard MATLAB Function for Standard DeviationDeviation
STD Standard deviation.STD Standard deviation. For vectors, STD(X) returns the standard deviation. For For vectors, STD(X) returns the standard deviation. For
matrices, STD(X) is a row vector containing the matrices, STD(X) is a row vector containing the standard deviation of each column. For N-D arrays, standard deviation of each column. For N-D arrays, STD(X) is the standard deviation of the elements along STD(X) is the standard deviation of the elements along the first non-singleton dimension of X.the first non-singleton dimension of X.
STD(X) normalizes by (N-1) where N is the sequence STD(X) normalizes by (N-1) where N is the sequence length. This makes STD(X).^2 the best unbiased length. This makes STD(X).^2 the best unbiased estimate of the variance if X is a sample from a normal estimate of the variance if X is a sample from a normal distribution.distribution.
Example: If X = [4 -2 1 9 5 7]Example: If X = [4 -2 1 9 5 7] then std(X) = 4 is standard deviation. This is a large then std(X) = 4 is standard deviation. This is a large
number which means that the data are spread out.number which means that the data are spread out.
February 28, 2005February 28, 2005 Lecture 11 - By Paul LinLecture 11 - By Paul Lin 1414
Mean and Standard DeviationMean and Standard Deviation
Example 4:Example 4: Mr. A purchased a new car and want Mr. A purchased a new car and want to find the MEAN and the Standard Deviation to find the MEAN and the Standard Deviation of gas consumption (miles per gallon) of gas consumption (miles per gallon) obtained in 10 test-runs.obtained in 10 test-runs.
1)1) Find the mean and standard deviation using Find the mean and standard deviation using MATLAB mean( ) and std ( ) functions.MATLAB mean( ) and std ( ) functions.
2)2) Find the mean and deviation using the Find the mean and deviation using the formula as shown below:formula as shown below:
N
iixN
Mean1
1
)1(
)(1 1
22
NN
xxNstd
N
i
N
iii
February 28, 2005February 28, 2005 Lecture 11 - By Paul LinLecture 11 - By Paul Lin 1515
Example 4: ContinueExample 4: Continue
Miles per gallon obtained in 10 test-runs:Miles per gallon obtained in 10 test-runs:%Miles Per Gallon%Miles Per Gallon
mpg = [20 22 23 22 23 22 21 20 20 22];mpg = [20 22 23 22 23 22 21 20 20 22];
% ex10_4.m% By M. Lin% Student Performance % Comparisonformat bank% Miles Per Gallonmpg = [20 22 23 22 23 22 21 20 20 22];N = length(mpg);
% calculation method 1avg_1 = mean(mpg) % 21.50std_1 = std(mpg) % 1.18% calculation method 2sum_2 = sum(mpg);avg_2 = sum(mpg)/N % 21.50std_2 = sqrt((N*sum(mpg.^2) - (sum_2)^2)/(N*(N-1)))%1.18format short
February 28, 2005February 28, 2005 Lecture 11 - By Paul LinLecture 11 - By Paul Lin 1616
10-3 Empirical Equation10-3 Empirical Equation – Race – Race Car Speed PredictionCar Speed Prediction
Example 5: A racing car is clocked at various times t Example 5: A racing car is clocked at various times t and velocities Vand velocities V
t = [0 5 10 15 20 25 30 35 40]; % Secondt = [0 5 10 15 20 25 30 35 40]; % Second
velocity = [24 33 62 77 105 123 151 170 188]; % m/secvelocity = [24 33 62 77 105 123 151 170 188]; % m/sec Determine the equation of a straight line Determine the equation of a straight line
constructed through the points plotted using constructed through the points plotted using MATLABMATLAB
Once the equation is determined, velocities at Once the equation is determined, velocities at intermediate values can be computed or intermediate values can be computed or estimated from this equationestimated from this equation
Reference: Engineering Fundamentals and Problem Solving, Arvid Edie, et. al., pp. 67-68, McGrawHill, 1979
February 28, 2005February 28, 2005 Lecture 11 - By Paul LinLecture 11 - By Paul Lin 1717
Empirical EquationEmpirical Equation – Race Car – Race Car Speed PredictionSpeed Prediction
Example 5: MATLAB ProgramExample 5: MATLAB Program% ex10_5.m% ex10_5.m
% By M. Lin% By M. Lin
t = [0 5 10 15 20 25 30 35 40];t = [0 5 10 15 20 25 30 35 40];
velocity = [24 33 62 77 105 velocity = [24 33 62 77 105 123 151 170 188];123 151 170 188];
plot(t, velocity,'o'), grid onplot(t, velocity,'o'), grid on
title(' Velocity vs Time');title(' Velocity vs Time');
xlabel('Time - second');xlabel('Time - second');
ylabel('Velocity - meter/sec')ylabel('Velocity - meter/sec')
hold onhold on
plot(t, velocity)plot(t, velocity)0 5 10 15 20 25 30 35 40
20
40
60
80
100
120
140
160
180
200 Velocity vs Time
Time - second
Velo
city
- m
eter
/sec
February 28, 2005February 28, 2005 Lecture 11 - By Paul LinLecture 11 - By Paul Lin 1818
Empirical EquationEmpirical Equation – Race Car – Race Car Speed PredictionSpeed Prediction
Example 5: MATLAB Example 5: MATLAB ProgramProgram
The linear equation The linear equation can be described as can be described as the slope-intercept the slope-intercept form form V = m*t +b;V = m*t +b;where m is the slope where m is the slope and b is the and b is the intercept intercept
Select point Select point A(10,60), point B(40, A(10,60), point B(40, 185)185)
0 5 10 15 20 25 30 35 4020
40
60
80
100
120
140
160
180
200 Velocity vs Time
Time - second
Velo
city
- m
eter
/sec
10
60 A
40
185
February 28, 2005February 28, 2005 Lecture 11 - By Paul LinLecture 11 - By Paul Lin 1919
Empirical EquationEmpirical Equation – Race Car – Race Car Speed PredictionSpeed Prediction
Example 5: MATLAB Program (continue)Example 5: MATLAB Program (continue) We substitute A(10,60), and B(40, 185) into the We substitute A(10,60), and B(40, 185) into the
equation V = m*t +b;equation V = m*t +b;to find m and b to find m and b 60 = m*10 + b ----- (1)60 = m*10 + b ----- (1)
185 = m*40 + b ---- (2)185 = m*40 + b ---- (2) We then solve the two equations for the two We then solve the two equations for the two
unknowns m and b:unknowns m and b: m = 4.2m = 4.2
b = 18.3b = 18.3 Now we have the equation Now we have the equation
V = 4.2 t + 18.3V = 4.2 t + 18.3
February 28, 2005February 28, 2005 Lecture 11 - By Paul LinLecture 11 - By Paul Lin 2020
Empirical EquationEmpirical Equation – Race Car – Race Car Speed PredictionSpeed Prediction
Example 5: MATLAB Program (continue)Example 5: MATLAB Program (continue)
t = [0 5 10 15 20 25 30 35 40];t = [0 5 10 15 20 25 30 35 40];velocity = [24 33 62 77 105 velocity = [24 33 62 77 105 123 151 170 188];123 151 170 188];plot(t, velocity,'o'), grid onplot(t, velocity,'o'), grid ontitle(' Velocity vs Time');title(' Velocity vs Time');xlabel('Time - second');xlabel('Time - second');ylabel('Velocity - meter/sec')ylabel('Velocity - meter/sec')hold onhold onplot(t, velocity)plot(t, velocity)m = 4.2;m = 4.2;b = 18.3;b = 18.3;t1 = 0:5:40;t1 = 0:5:40;V = 4.2*t1 + 18.3;V = 4.2*t1 + 18.3;hold onhold onplot(t1, V, 'r')plot(t1, V, 'r')
0 5 10 15 20 25 30 35 400
50
100
150
200 Velocity vs Time
Time - second
Vel
ocity
- m
eter
/sec
February 28, 2005February 28, 2005 Lecture 11 - By Paul LinLecture 11 - By Paul Lin 2121
SummarySummary
Introduction to Statistics Introduction to Statistics Statistical AnalysisStatistical Analysis
• Arithmetic MeanArithmetic Mean• VarianceVariance• Standard DeviationStandard Deviation
Empirical Linear EquationEmpirical Linear Equation