Introduction to MATLAB for Engineers, Third Edition Chapter 6 Model Building and Regression PowerPoint to accompany Copyright © 2010. The McGraw-Hill Companies,

Slides:



Advertisements
Similar presentations
Class 7.2: Graphical Analysis and Excel Solving Problems Using Graphical Analysis.
Advertisements

Correlation and regression
Copyright © 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 1 ~ Curve Fitting ~ Least Squares Regression Chapter.
1 Functions and Applications
Regression Analysis Module 3. Regression Regression is the attempt to explain the variation in a dependent variable using the variation in independent.
Chapter 10 Curve Fitting and Regression Analysis
EGR 105 Foundations of Engineering I
Excel Part III Curve-Fitting, Regression Section 8 Fall 2013 EGR 105 Foundations of Engineering I.
CITS2401 Computer Analysis & Visualisation
Regression Regression: Mathematical method for determining the best equation that reproduces a data set Linear Regression: Regression method applied with.
9. SIMPLE LINEAR REGESSION AND CORRELATION
Least Square Regression
Least Square Regression
EGR 105 Foundations of Engineering I Fall 2007 – week 7 Excel part 3 - regression.
The Islamic University of Gaza Faculty of Engineering Civil Engineering Department Numerical Analysis ECIV 3306 Chapter 17 Least Square Regression.
Part 4 Chapter 13 Linear Regression
EGR 105 Foundations of Engineering I Fall 2007 – week 7 Excel part 3 - regression.
Copyright © 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display. by Lale Yurttas, Texas A&M University Chapter 171 CURVE.
Math 227 Elementary Statistics Math 227 Elementary Statistics Sullivan, 4 th ed.
Introduction to MATLAB for Engineers, Third Edition William J. Palm III Chapter 7 Statistics, Probability, and Interpolation PowerPoint to accompany Copyright.
Copyright © 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display. by Lale Yurttas, Texas A&M University Chapter 171 Least.
Chapter 5 Plotting Data Curve Fitting, Good Graphing Practices Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Correlation and Linear Regression
McGraw-Hill/Irwin Copyright © 2010 by The McGraw-Hill Companies, Inc. All rights reserved. Chapter 13 Linear Regression and Correlation.
9 - 1 Intrinsically Linear Regression Chapter Introduction In Chapter 7 we discussed some deviations from the assumptions of the regression model.
Copyright © 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 1 ~ Curve Fitting ~ Least Squares Regression Chapter.
Introduction to Linear Regression and Correlation Analysis
Copyright © Cengage Learning. All rights reserved.
CMPS1371 Introduction to Computing for Engineers NUMERICAL METHODS.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 1 Part 4 Curve Fitting.
Chapter 12 Examining Relationships in Quantitative Research Copyright © 2013 by The McGraw-Hill Companies, Inc. All rights reserved. McGraw-Hill/Irwin.
Engineering Analysis ENG 3420 Fall 2009 Dan C. Marinescu Office: HEC 439 B Office hours: Tu-Th 11:00-12:00.
MECN 3500 Inter - Bayamon Lecture 9 Numerical Methods for Engineering MECN 3500 Professor: Dr. Omar E. Meza Castillo
Biostatistics Lecture 17 6/15 & 6/16/2015. Chapter 17 – Correlation & Regression Correlation (Pearson’s correlation coefficient) Linear Regression Multiple.
Curve Fitting and Regression EEE 244. Descriptive Statistics in MATLAB MATLAB has several built-in commands to compute and display descriptive statistics.
Chapter 8 Curve Fitting.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Introduction to MATLAB 7 for Engineers Chapter 5B Model.
ES 240: Scientific and Engineering Computation. Chapter 13: Linear Regression 13. 1: Statistical Review Uchechukwu Ofoegbu Temple University.
Examining Relationships in Quantitative Research
CHAPTER 3 Model Fitting. Introduction Possible tasks when analyzing a collection of data points: Fitting a selected model type or types to the data Choosing.
Lecture 10 2D plotting & curve fitting Subplots Other 2-D Plots Other 2-D Plots Curve fitting © 2007 Daniel Valentine. All rights reserved. Published by.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Introduction to MATLAB 7 for Engineers Chapter 5 Advanced.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. A Concise Introduction to MATLAB ® Chapter 5 Advanced.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Introduction to MATLAB 7 for Engineers Chapter 5B Model.
© Copyright McGraw-Hill Correlation and Regression CHAPTER 10.
11/20/2015ENGR 111A - Fall MatLab – Palm Chapter 5 Curve Fitting Class 14.1 Palm Chapter:
Revision: Pivot Table 1. Histogram 2. Trends 3. Linear 4. Exponential
Polynomials, Curve Fitting and Interpolation. In this chapter will study Polynomials – functions of a special form that arise often in science and engineering.
^ y = a + bx Stats Chapter 5 - Least Squares Regression
MODEL FITTING jiangyushan. Introduction The goal of model fitting is to choose values for the parameters in a function to best describe a set of data.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 1 Part 4 Chapter 15 General Least Squares and Non- Linear.
Chapter 13 Objectives Familiarizing yourself with some basic descriptive statistics and the normal distribution. Knowing how to compute the slope and intercept.
Copyright © 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 1 ~ Curve Fitting ~ Least Squares Regression.
Engineering Analysis ENG 3420 Fall 2009 Dan C. Marinescu Office: HEC 439 B Office hours: Tu-Th 11:00-12:00.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Introduction to MATLAB 7 for Engineers Chapter 5 Advanced.
Copyright © 2013, 2010 and 2007 Pearson Education, Inc. Chapter Describing the Relation between Two Variables 4.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Applied Numerical Methods With MATLAB ® for Engineers.
Introduction to Programming for Mechanical Engineers
Chapter 4 Basic Estimation Techniques
1 Functions and Applications
Part 5 - Chapter
Part 5 - Chapter 17.
Regression Chapter 6 I Introduction to Regression
Lecture 10 2D plotting & curve fitting
Chapter 12 Curve Fitting : Fitting a Straight Line Gab-Byung Chae
Part 5 - Chapter 17.
MatLab – Palm Chapter 5 Curve Fitting
^ y = a + bx Stats Chapter 5 - Least Squares Regression
Least Square Regression
Presentation transcript:

Introduction to MATLAB for Engineers, Third Edition Chapter 6 Model Building and Regression PowerPoint to accompany Copyright © The McGraw-Hill Companies, Inc.

Using the Linear, Power, and Exponential Functions to Describe data. Each function gives a straight line when plotted using a specific set of axes: 1. The linear function y  mx  b gives a straight line when plotted on rectilinear axes. Its slope is m and its intercept is b. 2. The power function y  bx m gives a straight line when plotted on log-log axes. 3. The exponential function y  b(10) mx and its equivalent form y  be mx give a straight line when plotted on a semilog plot whose y-axis is logarithmic. 6-2 More? See pages

Function Discovery. The power function y  2x  0  5 and the exponential function y  10 1  x plotted on linear, semi- log, and log-log axes.  6-3

Steps for Function Discovery 1.Examine the data near the origin. The exponential function can never pass through the origin (unless of course b  0, which is a trivial case). (See Figure 6.1–1 for examples with b  1.) The linear function can pass through the origin only if b  0. The power function can pass through the origin but only if m  0. (See Figure 6.1–2 for examples with b  1.) 6-4

Examples of exponential functions. Figure 6.1–1 6-5

Examples of power functions. Figure 6.1–2 6-6

2. Plot the data using rectilinear scales. If it forms a straight line, then it can be represented by the linear function and you are finished. Otherwise, if you have data at x  0, then a. If y(0)  0, try the power function. b. If y(0)  0, try the exponential function. If data is not given for x  0, proceed to step Steps for Function Discovery (continued) (continued…)

3. If you suspect a power function, plot the data using log- log scales. Only a power function will form a straight line on a log-log plot. If you suspect an exponential function, plot the data using the semilog scales. Only an exponential function will form a straight line on a semilog plot. 6-8 Steps for Function Discovery (continued) (continued…)

4. In function discovery applications, we use the log-log and semilog plots only to identify the function type, but not to find the coefficients b and m. The reason is that it is difficult to interpolate on log scales. 6-9 Steps for Function Discovery (continued)

Command p = polyfit(x,y,n) Description Fits a polynomial of degree n to data described by the vectors x and y, where x is the independent variable. Returns a row vector p of length n + 1 that contains the polynomial coefficients in order of descending powers. The polyfit function. Table 6.1–1 6-10

Using the polyfit Function to Fit Equations to Data. Syntax: p = polyfit(x,y,n) where x and y contain the data, n is the order of the polynomial to be fitted, and p is the vector of polynomial coefficients. The linear function: y = mx + b. In this case the variables w and z in the polynomial w = p 1 z+ p 2 are the original data variables x and y, and we can find the linear function that fits the data by typing p = polyfit(x,y,1). The first element p 1 of the vector p will be m, and the second element p 2 will be b. 6-11

The power function: y  bx m. In this case log 10 y  m log 10 x  log 10 b which has the form w  p 1 z  p 2 where the polynomial variables w and z are related to the original data variables x and y by w  log 10 y and z  log 10 x. Thus we can find the power function that fits the data by typing p = polyfit(log10(x),log10(y),1) The first element p 1 of the vector p will be m, and the second element p 2 will be log 10 b. We can find b from b  10 p

The exponential function: y  b(10) mx. In this case log 10 y  mx  log 10 b which has the form w  p 1 z  p 2 where the polynomial variables w and z are related to the original data variables x and y by w  log 10 y and z  x. We can find the exponential function that fits the data by typing p = polyfit(x, log10(y),1) The first element p 1 of the vector p will be m, and the second element p 2 will be log 10 b. We can find b from b  10 p

Fitting an exponential function. Temperature of a cooling cup of coffee, plotted on various coordinates. Example Figure on page

Fitting a power function. An experiment to verify Torricelli’s principle. Example Figure on page

Flow rate and fill time for a coffee pot. Figure on page

The Least Squares Criterion: used to fit a function f (x). It minimizes the sum of the squares of the residuals, J. J is defined as We can use this criterion to compare the quality of the curve fit for two or more functions used to describe the same data. The function that gives the smallest J value gives the best fit. m  i1i1 J  [ f (x i ) – y i ]

Illustration of the least squares criterion. 6-18

The least squares fit for the example data See pages

p = polyfit(x,y,n) Fits a polynomial of degree n to data described by the vectors x and y, where x is the independent variable. Returns a row vector p of length n+1 that contains the polynomial coefficients in order of descending powers The polyfit function is based on the least-squares method. Its syntax is See page 273, Table

Regression using polynomials of first through fourth degree. Figure on page

Beware of using polynomials of high degree. An example of a fifth-degree polynomial that passes through all six data points but exhibits large excursions between points. Figure 6.2-2, page

Assessing the Quality of a Curve Fit: Denote the sum of the squares of the deviation of the y values from their mean y by S, which can be computed from (y i – y ) 2 (6.2–2) m  i1i1 S S  6-23

This formula can be used to compute another measure of the quality of the curve fit, the coefficient of determination, also known as the r-squared value. It is defined as (6.2-3) J S r 2  1  6-24 The value of S indicates how much the data is spread around the mean, and the value of J indicates how much of the data spread is unaccounted for by the model. Thus the ratio J / S indicates the fractional variation unaccounted for by the model.

For a perfect fit, J  0 and thus r 2  1. Thus the closer r 2 is to 1, the better the fit. The largest r 2 can be is 1. It is possible for J to be larger than S, and thus it is possible for r 2 to be negative. Such cases, however, are indicative of a very poor model that should not be used. As a rule of thumb, a good fit accounts for at least 99 percent of the data variation. This value corresponds to r 2  More? See pages

Scaling the Data The effect of computational errors in computing the coefficients can be lessened by properly scaling the x values. You can scale the data yourself before using polyfit. Some common scaling methods are 1.Subtract the minimum x value or the mean x value from the x data, if the range of x is small, or 2.Divide the x values by the maximum value or the mean value, if the range is large More? See pages

Effect of coefficient accuracy on a sixth-degree polynomial. Top graph: 14 decimal-place accuracy. Bottom graph: 8 decimal-place accuracy. 6-27

Avoiding high degree polynomials: Use of two cubics to fit data. 6-28

Using Residuals: Residual plots of four models. Figure 6.2-3, page See pages

Linear-in-Parameters Regression: Comparison of first- and second-order model fits. Figure 6.2-4, page See pages

Basic Fitting Interface MATLAB supports curve fitting through the Basic Fitting interface. Using this interface, you can quickly perform basic curve fitting tasks within the same easy-to-use environment. The interface is designed so that you can:  Fit data using a cubic spline or a polynomial up to degree 10.  Plot multiple fits simultaneously for a given data set.  Plot the residuals.  Examine the numerical results of a fit.  Interpolate or extrapolate a fit.  Annotate the plot with the numerical fit results and the norm of residuals.  Save the fit and evaluated results to the MATLAB workspace. 6-31

The Basic Fitting interface. Figure 6.3-1, page

A figure produced by the Basic Fitting interface. Figure 6.3-2, page More? See pages