Mechanical Engineering - 22.302 ME Lab I ME 22.302 Mechanical Lab I Numerical Methods 1 Volt Sine Series1 1.5 1 97 93 89 101 85 81 77 73 69 65 61 57 53 49 45 41 37 33 29 25 9 21 5 17 1 0 13 SIN(X) 0.5 -0.5 Normalized Squared Function -1 -1.5 0.07 0.06 2*PI 0.05 0.04 0.03 0.02 0.01 Dr. Peter Avitabile University of Massachusetts Lowell Numerical Methods - 010504 - 1 96 91 86 81 76 71 66 61 56 51 46 41 36 31 26 21 16 11 6 1 0 Copyright © 2001 Mechanical Engineering - 22.302 ME Lab I Some brief notes on numerical methods are included in this section Root Mean Square (RMS) Differentiation of a Signal Integration of a Signal Least Squares Fit of Data Dr. Peter Avitabile University of Massachusetts Lowell Numerical Methods - 010504 - 2 Copyright © 2001 Mechanical Engineering - 22.302 ME Lab I Root Mean Square (RMS) of a Sine Wave 1 T 2 RMS = y ( t ) dt ∫ 0 T Peak to Peak Peak T = Period Dr. Peter Avitabile University of Massachusetts Lowell Numerical Methods - 010504 - 3 Copyright © 2001 Mechanical Engineering - 22.302 ME Lab I A sine wave can be written as a continuous function. This sine wave can be written in discrete form for small delta x increments To evaluate the RMS, the sine wave needs to be first squared and then multiplied by each of the delta increments. These values are summed, divided by the total time and then a square root taken. 1 Volt Sine Series1 1.5 1 Normalized Squared Function 0.07 0.06 97 101 93 89 85 81 77 73 69 65 61 57 53 49 45 41 37 33 29 25 21 17 9 13 5 0 1 SIN(X) 0.5 0.05 -0.5 0.04 -1 0.03 0.02 -1.5 2*PI 0.01 Dr. Peter Avitabile University of Massachusetts Lowell Numerical Methods - 010504 - 4 96 91 86 81 76 71 66 61 56 51 46 41 36 31 26 21 16 6 11 1 0 Copyright © 2001 Mechanical Engineering - 22.302 ME Lab I In Excel, the data values are created and used to form a sine. These values are squared and divided by the spacing (increment). A summation of the values are divided by the entire time length. The square root of this yields the RMS value of the signal 3 1 2 Dr. Peter Avitabile University of Massachusetts Lowell Numerical Methods - 010504 - 5 Copyright © 2001 Mechanical Engineering - 22.302 ME Lab I Numerical Differentiation needs to be performed in many cases SLOPE = dy ∆y yi +1 − yi = = dx ∆x x i +1 − x i There are many different methods available for numerical processing Dr. Peter Avitabile University of Massachusetts Lowell Numerical Methods - 010504 - 6 Copyright © 2001 Mechanical Engineering - 22.302 ME Lab I 1st Forward Differentiation dy ∆y yi +1 − yi SLOPE = = = dx ∆x x i +1 − x i yi+1 yi x i x i+1 1st Backward Differentiation yi dy ∆y yi − yi−1 SLOPE = = = dx ∆x x i − x i −1 yi−1 x i−1 x i 1st Central Difference SLOPE = Dr. Peter Avitabile dy ∆y yi+1 − yi −1 = = dx ∆x x i+1 − x i−1 University of Massachusetts Lowell Numerical Methods - 010504 - 7 Copyright © 2001 Mechanical Engineering - 22.302 ME Lab I 2nd Central Difference Differentiation – Equal Spacing d 2 y ∆2 y yi+1 − 2 yi + yi−1 = 2= 2 dx ∆x ∆x 2 Initial conditions need to be specified for the start of the numerical process. This may have an effect on the accuracy of the results obtained. Dr. Peter Avitabile University of Massachusetts Lowell Numerical Methods - 010504 - 8 Copyright © 2001 Mechanical Engineering - 22.302 ME Lab I Numerical Integration - Rectangular Rule Ii = Ii−1 + yi (x i+1 − x i ) The smaller the x increment, the closer the result approaches the “actual” theoretical value Dr. Peter Avitabile University of Massachusetts Lowell Numerical Methods - 010504 - 9 Copyright © 2001 Mechanical Engineering - 22.302 ME Lab I Numerical Integration - Trapezoidal Rule Ii = Ii−1 + yi +1 + yi (x i+1 − x i ) 2 The trapezoidal approach is more accurate than the rectangular approach and is the preferred method Dr. Peter Avitabile University of Massachusetts Lowell Numerical Methods - 010504 - 10 Copyright © 2001 Mechanical Engineering - 22.302 ME Lab I Least Squares Fit of Data - Regression Analysis Y X Many times it is necessary to fit the best line to a set of collected data. This is typically performed using a least squares error minimization of this data to approximate the parameters that best describe the line. A straight line is shown next - this can be extended to any order polynomial. Dr. Peter Avitabile University of Massachusetts Lowell Numerical Methods - 010504 - 11 Copyright © 2001 Mechanical Engineering - 22.302 ME Lab I Least Squares Fit - Straight Line --- y=ax+b An error term is generated that describes the data in relation to the line describing the data. ei = yi − (ax i + b ) The sum of the errors will, in the limit, approach zero. Therefore, the sum of the square of the error is typically used z = e12 + e 2 2 + e32 + L n z = ∑ [yi − (ax i + b )]2 i =1 Dr. Peter Avitabile University of Massachusetts Lowell Numerical Methods - 010504 - 12 Copyright © 2001 Mechanical Engineering - 22.302 ME Lab I Least Squares Fit - Straight Line --- y=ax+b To minimize the error, take the derivative of z WRT a and b n ∂z = −2∑ x i [yi − (ax i + b )] = 0 ∂a i =1 n ∂z = −2∑ [yi − (ax i + b )] = 0 ∂b i =1 This can be recast as n n i =1 i =1 n a ∑ x i + bn = ∑ yi n n a ∑ x i + b∑ x i = ∑ x i yi 2 i =1 Dr. Peter Avitabile University of Massachusetts Lowell i =1 i =1 Numerical Methods - 010504 - 13 Copyright © 2001 Mechanical Engineering - 22.302 ME Lab I Least Squares Fit - Straight Line --- y=ax+b The Sum of the Squares Error (SSE) is an indicator of the goodness of the fit. Smaller SSE indicates a better fit n SSE = ∑ [yi − f (x i )]2 i =1 Another indicator is the R-Squared Value. Values approaching 1.0 indicate a good fit SSE r = 1− SST 2 n SST = ∑ [yi − y]2 i =1 Dr. Peter Avitabile University of Massachusetts Lowell Numerical Methods - 010504 - 14 Copyright © 2001 Mechanical Engineering - 22.302 ME Lab I Least Squares Fit - Straight Line using Alternate Coordinates The data may not always be best described by a linear fit in recatngular coordinates. A higher order model may be needed. However, many times a change in the coordinate system may result in a form that is best described by a straight line. Equation Type Exponential Logarithmic Power Dr. Peter Avitabile Equation Coordinate System y = ae bx Log Y vs X y = a ln x + b y = ax b University of Massachusetts Lowell Y vs Log X Log Y vs Log X Numerical Methods - 010504 - 15 Copyright © 2001 Mechanical Engineering - 22.302 ME Lab I Least Squares Fit - Matrix Formulation The same least squares minimization problem can be formulated with a matrix approach using MATLAB. The basic equations can be cast as y1 = ax1 + b y 2 = ax 2 + b {y} = [{x} y3 = ax 3 + b M Dr. Peter Avitabile to find the coefficients a and b University of Massachusetts Lowell [ a a {1}] = [coef ] b b ] −1 a T T [ ] [ ] [ ] = coef coef coef {y} b Numerical Methods - 010504 - 16 Copyright © 2001