- 79 Views
- Uploaded on
- Presentation posted in: General

CPET 190

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.

- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -

Problem Solving with MATLAB

Lecture 11

http://www.ecet.ipfw.edu/~lin

Lecture 11 - By Paul Lin

11-1 Introduction to Statistics

11-2 Statistical Analysis

- Arithmetic Mean
- Variance
- Standard Deviation
11-3 Empirical Linear Equation

Lecture 11 - By Paul Lin

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

Lecture 11 - By Paul Lin

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
- Measure of central tendency (mean or average)
- Measure of variation (standard deviation)
- Normal curve
- Linear regression

Lecture 11 - By Paul Lin

- 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????

Lecture 11 - By Paul Lin

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.

Lecture 11 - By Paul Lin

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

% 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

>> Student B is better than student A

B_avg = 91.80

Lecture 11 - By Paul Lin

- 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)

Lecture 11 - By Paul Lin

- Arithmetic mean or average value
Where N measurements are designated x1, x2, ..

Or in the closed form as

Lecture 11 - By Paul Lin

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.

Lecture 11 - By Paul Lin

- The variance is a measure of how spread out a distribution is.
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

Lecture 11 - By Paul Lin

- 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.

Lecture 11 - By Paul Lin

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.

Lecture 11 - By Paul Lin

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.

- Find the mean and standard deviation using MATLAB mean( ) and std ( ) functions.
- Find the mean and deviation using the formula as shown below:

Lecture 11 - By Paul Lin

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);

% 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

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

Lecture 11 - By Paul Lin

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)

Lecture 11 - By Paul Lin

Example 5: MATLAB 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

- Select point A(10,60), point B(40, 185)

185

A

60

10

40

Lecture 11 - By Paul Lin

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

Lecture 11 - By Paul Lin

Example 5: MATLAB Program (continue)

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')

Lecture 11 - By Paul Lin

- Introduction to Statistics
- Statistical Analysis
- Arithmetic Mean
- Variance
- Standard Deviation

- Empirical Linear Equation

Lecture 11 - By Paul Lin