Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
CPET 190 Problem Solving with MATLAB Lecture 11 http://www.ecet.ipfw.edu/~lin February 28, 2005 Lecture 11 - By Paul Lin 1 Lecture 11: Solving Basic Statistics Problems 11-1 Introduction to Statistics 11-2 Statistical Analysis • Arithmetic Mean • Variance • Standard Deviation 11-3 Empirical Linear Equation February 28, 2005 Lecture 11 - By Paul Lin 2 11-1 Introduction to Statistics Origin of Statistics (18th century) • Game of chance, and what is now called political sciences • Descriptive statistics: numerical description of political units (cities, provinces, countries, etc); presentation of data in tables and charts; summarization of data by means of numerical description Reference: Chapter 14 Statistics, Engineering Fundamentals and Problem Solving, Arvid Edie, et. al. McGrawHill, 1979 February 28, 2005 Lecture 11 - By Paul Lin 3 11-1 Introduction to Statistics Statistics Inference • Make generalization about collected data using carefully controlled variables Applications of Statistics • Decision making • Gaming industries • Comparison of the efficiency of production processes • Quality Control February 28, 2005 Measure of central tendency (mean or average) Measure of variation (standard deviation) Normal curve Linear regression Lecture 11 - By Paul Lin 4 11-1 Introduction to Statistics Basic Statistical Analysis • A large set of measured data or numbers • Average value (or arithmetic mean) • Standard Deviation • Study and summarize the results of the measured data, and more Example 1: Student performance comparison Two ECET students are enrolled in the CPET 190 and each completed five quizzes: qz1, qz2, qz3, qz4, and qz5. The grades are in the array format: • A = [82 61 88 78 80]; • B =[94 98 92 90 85]; Student 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.80 Statistical Inference: Student B Better Than Student A???? February 28, 2005 Lecture 11 - By Paul Lin 5 11-1 Introduction to Statistics Example 1: Student performance comparison (continue) Statistical Inference: Student B Better Than Student A???? Two Possible Answers: • Student B’s average grade 91.80 higher than A’s average grade 71.80, so that student B is a better student? Not quite true. • Student B may be better than A. This could be a more accurate answer. February 28, 2005 Lecture 11 - By Paul Lin 6 Example 1: The MATLAB Solution % ex10_1.m % By M. Lin % Student Performance Comparison format bank % 2 digits A = [82 61 88 78 80]; B =[94 98 92 90 85]; A_total = 0; B_total = 0; for n = 1: length(A) A_total = A_total + A(n); end A_avg = A_total/length(A) %71.80 for n = 1: length(B) B_total = B_total + B(n); end B_avg = B_total/length(B) % 91.80 February 28, 2005 if A_avg > B_avg; disp('Student A is better than student B') A_avg else disp('Student B is better than student A') B_avg end format short % 4 digits >> Student B is better than student A B_avg = Lecture 11 - By Paul Lin 91.80 7 11-2 Statistical Analysis Statistical Analysis • Data grouping and classifying data • Measures of tendency Arithmetic mean or average value. • Measures of variation Variance Standard Deviation • Predict or forecast the outcome of certain events Linear regression (the simplest one) February 28, 2005 Lecture 11 - By Paul Lin 8 11-2 Statistical Analysis Arithmetic mean or average value x1 x2 x3 ... xn Mean N Where N measurements are designated x1 , x2 , .. Or in the closed form as 1 Mean N February 28, 2005 N x i 1 Lecture 11 - By Paul Lin i 9 MEAN() - MATLAB Function for Calculating Average or Mean Values MEAN Average or mean value. For vectors, MEAN(X) is the mean value of the elements in X. 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 the elements along the first non-singleton dimension of X. Example 2: If X = [0 1 2 3 4 5], then mean(X) = 2.5000 >> X = [0 1 2 3 4 5]; >> mean(X) ans = 2.5000 Verify the answer by hand: (0 + 1 + 2 + 3 + 4 + 5)/6 = 15/6 = 2.5. February 28, 2005 Lecture 11 - By Paul Lin 10 Variance The variance is a measure of how spread out a distribution is. 2 2 ( x ) N Where x is each measurement, μ is the mean, and N is the number of measurement It is computed as the average squared deviation of each number from its mean. Example 3: we measure three resistors in a bin and read the resistances 1 ohm, 2 ohms, and 3 ohms, the mean is (1+2+3)/3, or 2 ohms, and the variance is 2 2 2 1 2 ( 2 2 ) ( 3 2 ) 2 0.667 3 February 28, 2005 Lecture 11 - By Paul Lin 11 Standard Deviation A measure of the dispersion (or spread) of a set of data from its mean. The more spread apart the data is, the higher the deviation. A statistic about how tightly all the various measurement are clustered around the mean in a set of data. When the examples are pretty tightly bunched together and the bell-shaped curve is steep, the standard deviation is small. When the examples are spread apart and the bell curve is relatively flat, that tells you have a relatively large standard deviation. N std February 28, 2005 N N x ( xi ) 2 i 1 2 i i 1 N ( N 1) Lecture 11 - By Paul Lin 12 MATLAB Function for Standard Deviation STD Standard deviation. For vectors, STD(X) returns the standard deviation. For matrices, STD(X) is a row vector containing the standard deviation of each column. For N-D arrays, STD(X) is the standard deviation of the elements along the first non-singleton dimension of X. STD(X) normalizes by (N-1) where N is the sequence length. This makes STD(X).^2 the best unbiased estimate of the variance if X is a sample from a normal distribution. Example: If X = [4 -2 1 9 5 7] then std(X) = 4 is standard deviation. This is a large number which means that the data are spread out. February 28, 2005 Lecture 11 - By Paul Lin 13 Mean and Standard Deviation Example 4: Mr. A purchased a new car and want to find the MEAN and the Standard Deviation of gas consumption (miles per gallon) obtained in 10 test-runs. 1) Find the mean and standard deviation using MATLAB mean( ) and std ( ) functions. 2) Find the mean and deviation using the formula as shown below: 1 Mean N February 28, 2005 N xi i 1 N std Lecture 11 - By Paul Lin N N x ( xi ) 2 i 1 2 i i 1 N ( N 1) 14 Example 4: Continue Miles per gallon obtained in 10 test-runs: %Miles Per Gallon mpg = [20 22 23 22 23 22 21 20 20 22]; % ex10_4.m % By M. Lin % Student Performance % Comparison format bank % Miles Per Gallon mpg = [20 22 23 22 23 22 21 20 20 22]; N = length(mpg); February 28, 2005 % calculation method 1 avg_1 = mean(mpg) % 21.50 std_1 = std(mpg) % 1.18 % calculation method 2 sum_2 = sum(mpg); avg_2 = sum(mpg)/N % 21.50 std_2 = sqrt((N*sum(mpg.^2) (sum_2)^2)/(N*(N-1))) %1.18 format short Lecture 11 - By Paul Lin 15 10-3 Empirical Equation – Race Car Speed Prediction Example 5: A racing car is clocked at various times t and velocities V t = [0 5 10 15 20 25 30 35 40]; % Second velocity = [24 33 62 77 105 123 151 170 188]; % m/sec Determine the equation of a straight line constructed through the points plotted using MATLAB Once the equation is determined, velocities at intermediate values can be computed or estimated from this equation Reference: Engineering Fundamentals and Problem Solving, Arvid Edie, et. al., pp. 67-68, McGrawHill, 1979 February 28, 2005 Lecture 11 - By Paul Lin 16 Empirical Equation – Race Car Speed Prediction February 28, 2005 Velocity vs Time 200 180 160 Velocity - meter/sec Example 5: MATLAB Program % ex10_5.m % By M. Lin t = [0 5 10 15 20 25 30 35 40]; velocity = [24 33 62 77 105 123 151 170 188]; plot(t, velocity,'o'), grid on title(' Velocity vs Time'); xlabel('Time - second'); ylabel('Velocity - meter/sec') hold on plot(t, velocity) 140 120 100 80 60 40 20 0 Lecture 11 - By Paul Lin 5 10 15 20 25 Time - second 30 35 40 17 Empirical Equation – Race Car Speed Prediction Velocity vs Time 200 180 160 Velocity - meter/sec Example 5: MATLAB 185 Program The linear equation can be described as the slope-intercept form V = m*t +b; where m is the slope and b is the intercept 60 Select point A(10,60), point B(40, 185) 140 120 100 80 A 60 40 20 0 5 10 10 February 28, 2005 Lecture 11 - By Paul Lin 15 20 25 Time - second 30 35 40 40 18 Empirical Equation – Race Car Speed Prediction Example 5: MATLAB Program (continue) We substitute A(10,60), and B(40, 185) into the equation V = m*t +b; to find m and b 60 = m*10 + b ----- (1) 185 = m*40 + b ---- (2) We then solve the two equations for the two unknowns m and b: m = 4.2 b = 18.3 Now we have the equation V = 4.2 t + 18.3 February 28, 2005 Lecture 11 - By Paul Lin 19 Empirical Equation – Race Car Speed Prediction Example 5: MATLAB Program (continue) February 28, 2005 Velocity vs Time 200 150 Velocity - meter/sec t = [0 5 10 15 20 25 30 35 40]; velocity = [24 33 62 77 105 123 151 170 188]; plot(t, velocity,'o'), grid on title(' Velocity vs Time'); xlabel('Time - second'); ylabel('Velocity - meter/sec') hold on plot(t, velocity) m = 4.2; b = 18.3; t1 = 0:5:40; V = 4.2*t1 + 18.3; hold on plot(t1, V, 'r') 100 50 0 0 5 Lecture 11 - By Paul Lin 10 15 20 25 Time - second 30 35 40 20 Summary February 28, 2005 Introduction to Statistics Statistical Analysis • Arithmetic Mean • Variance • Standard Deviation Empirical Linear Equation Lecture 11 - By Paul Lin 21