MECN 3500 Inter - Bayamon Lecture 9 Numerical Methods for Engineering MECN 3500 Professor: Dr. Omar E. Meza Castillo Department of Mechanical Engineering Inter American University of Puerto Rico Bayamon Campus
Lecture 9 MECN 3500 Inter - Bayamon 2 Tentative Lectures Schedule TopicLecture Mathematical Modeling and Engineering Problem Solving 1 Introduction to Matlab 2 Numerical Error 3 Root Finding System of Linear Equations 7-8 Least Square Curve Fitting 9 Polynomial Interpolation Numerical Integration Ordinary Differential Equations
Lecture 9 MECN 3500 Inter - Bayamon Least-Squares Regression Curve Fitting 3
Lecture 9 MECN 3500 Inter - Bayamon To Describes techniques to fit curves (curve fitting) to discrete data to obtain intermediate estimates. 4 Course Objectives
Lecture 9 MECN 3500 Inter - Bayamon Curve fitting techniques are used to fit curves to data to obtain intermediate estimates or to derive a simpler function from a complicated function. Least squares regression is used when the data exhibits a significant degree of error or noise. Interpolation is used to fit curves that pass directly through each of the points. Introduction 5
Lecture 9 MECN 3500 Inter - Bayamon Least-squares regression techniques used to fit a curve to experimental data. These techniques used to derive an approximate function that fits the shape or general trend of the data. Techniques: linear regression, polynomial regression, multiple linear regression Linear Regression 6
Lecture 9 MECN 3500 Inter - Bayamon Linear Regression Fit a straight line to a set of paired observations (x 1,y 1 ), (x 2,y 2 ), …, (x n,y n ) The mathematical expression for the straight line is y = a 0 + a 1 x + e e is called the error or “residual” The residual is the difference between the observation and the line: e = y a 0 a 1 x What are the values of a 0 and a 1 ? 7
Lecture 9 MECN 3500 Inter - Bayamon 1.Minimize the sum of the residual errors Criteria for a Best Fit NO GOOD 8
Lecture 9 MECN 3500 Inter - Bayamon Criteria for a Best Fit 2.Minimize the sum of the absolute values of the residual errors NO GOOD 9
Lecture 9 MECN 3500 Inter - Bayamon Criteria for a Best Fit 3.Minimax: minimize the maximum error NO GOOD 10
Lecture 9 MECN 3500 Inter - Bayamon Criteria for a Best Fit 11 4.Minimize the sum of the squares of the residuals This criterion yields a unique line for a given set of data.
Lecture 9 MECN 3500 Inter - Bayamon Least-Squares Fit of a Straight Line 12 To determine the values of a 0 and a 1, differentiate S r with respect to each of the coefficients and set to zero: The equations become: The normal equations are
Lecture 9 MECN 3500 Inter - Bayamon Least-Squares Fit of a Straight Line 13 The slope and the y-intercept are given by y = a 0 + a 1 x + e a 0 is the intercept a 1 is the slope
Lecture 9 MECN 3500 Inter - Bayamon Least-Squares Fit of a Straight Line 14 The slope and the y-intercept are given by y = a 0 + a 1 x + e a 0 is the intercept a 1 is the slope
Lecture 9 MECN 3500 Inter - Bayamon Example Fit a straight line to the data xixi yiyi
Lecture 9 MECN 3500 Inter - Bayamon 16
Lecture 9 MECN 3500 Inter - Bayamon Quantification of Error of Linear Regression 17 To quantify the error reduction due to describing the data in terms of a straight line, we use the coefficient of determination which is defined as It represents the fraction of variability in y that can be explained by the variability in x (how close the points are to the line). For r 2 = 1, it signifies the line explains 100% of the variability of the data.
Lecture 9 MECN 3500 Inter - Bayamon Example Compute the coefficient of determination for the linear regression in previous example S t = S r = r 2 = This indicates that 86.8% of the original uncertainty is explained by the linear model. Answer
Lecture 9 MECN 3500 Inter - Bayamon Linearization of Nonlinear Relationships 19 Transformations can be used to express the data in a form that is compatible with the linear regression.
Lecture 9 MECN 3500 Inter - Bayamon Linearization of Nonlinear Relationships 20 Example 1: Suppose the relationship between x and y is It can be linearized by taking the ln of both sides: Example 2: Consider It can be transform into the linear form
Lecture 9 MECN 3500 Inter - Bayamon Linearization of Nonlinear Relationships 21 Example 3: Consider It can be linearized by inverting both sides
Lecture 9 MECN 3500 Inter - Bayamon Linearization of Nonlinear Relationships 22
Lecture 9 MECN 3500 Inter - Bayamon Example Fit to the data Answer xy x'y'
Lecture 9 MECN 3500 Inter - Bayamon Polynomial Regression 24 We need to fit a polynomial to data using polynomial regression. A second-order polynomial or quadratic fit is y = a 0 + a 1 x + a 2 x 2 + The sum of squares of the residues: Differentiate S r with respect to all parameters:
Lecture 9 MECN 3500 Inter - Bayamon Polynomial Regression 25 Set the partials to zero and arrange These equations are called the normal equations. They form a system of linear equations with 3 equations and 3 unknowns. In general, an mth order polynomial requires solving a system of m+1 linear equations.
Lecture 9 MECN 3500 Inter - Bayamon 26
Lecture 9 MECN 3500 Inter - Bayamon Example Fit a second-order polynomial to the data xy
Lecture 9 MECN 3500 Inter - Bayamon Multiple Linear Regression 28 Multiple Linear Regression The function y is a linear function of 2 or more independent variables, such as y = a 0 + a 1 x 1 + a 2 x 2 + The sum of the squares of the residuals To minimize S r,
Lecture 9 MECN 3500 Inter - Bayamon Multiple Linear Regression 29 The normal equations are
Lecture 9 MECN 3500 Inter - Bayamon 30
Lecture 9 MECN 3500 Inter - Bayamon Example Fit the data with multiple linear regression x1x1 x2x2 y
Lecture 9 MECN 3500 Inter - Bayamon Regression in Matlab and Excel 32 Use the polyfit function Regression in Excel Use Add Trendline Regression in Matlab
Lecture 9 MECN 3500 Inter - Bayamon Homework7 Omar E. Meza Castillo Ph.D. 33