Part six: Numerical differentiation and numerical integration Numerical integration formulas. Rectangle rule = = 21.1 Trapezoidal rule = 21.2 Simpson 1/3 = 21.2.3 Simpson 3/8 = =,,,, (21.3) (21.10) (21.15) (21.18) = (21.20) Numerical integration key points. Left hand side above formulas are for rule single application (eg..3,..15,..20) Right hand side above formulas are for rule multiple application (eg..10,..18) Lower bound of integration: a Upper bound of integration: b Keep in mind that if a single rule is being used in the computation of an area then all x axis points used in the evaluation of the function must be equidistant from each other. A.Cervantes MN Summary Page 1
Single application of Rectangle rule There is a single evaluation of the function: x m is located at the middle point between a and b = a b Single application of Trapezoidal rule There are two evaluations of the function:, Each value of x for the evaluation points coincide with the integration bounds a b Single application of Simpson 1/3 rule There are three evaluations of the function:,, x 0 and x 2 coincide with the integration bounds a b Single application of Simpson 3/8 rule There are four evaluations of the function:,,, x 0 and x 3 coincide with the integration bounds a b A.Cervantes MN Summary Page 2
Multiple application of Rectangle rule Rectangle rule sampled points: For n applications of rectangle rule we ll have n samples First sample x location: x1 = a + inc /2 Example for 4 rectangles: n=4 1111111111111222222222222233333333333334444444444444 a b x 1 x 2 x 3 x 4 Multiple application of Trapezoidal rule Trapezoidal rule sampled points:, For n applications of trapezoidal rule we ll have 2n samples Each value of x for the evaluation points coincide with the integration bounds Example for 4 trapezoids: n=4 1111111111111222222222222233333333333334444444444444 a b x 0 x 1 x 2 x 3 x 1 x 2 x 3 x 4 Multiple application of Simpson 1/3 rule There are three evaluations of the function:,, x 0 and x 2 coincide with the integration bounds a b A.Cervantes MN Summary Page 3
Multiple application of Simpson 3/8 rule There are four evaluations of the function:,,, x 0 and x 3 coincide with the integration bounds a b Chapter 3 Absolute true error = E t = true value calculated value (3.2) Absolute relative (fractional) true error = Absolute relative (%) true error = %= 100% (3.3) Part two: Roots 5.2 Bisection method (closed method) Open methods 6.1 Fixed point simple iteration method Given f(x), equate f(x) to zero and solve for any x in order to get x = g(x) = ) (6.2) Example1: 2+3=0 = Example2: sen x = 0 x = sen x + x Convergencia por método gráfico de las dos curvas Reformular f(x) = 0 como = entonces graficar = y = 6.2 Newton-Raphson method From figure 6.5 we get the slope: = = (6.6) A.Cervantes MN Summary Page 4
6.3 Secant method Having an additional initial point the rate of change is used as an aprox of f (x) = (6.7) 6.3.3 Método de la secante modificado = (6.8) A.Cervantes MN Summary Page 5
Systems of linear equations. *Inverse of a Matrix using Minors, Cofactors and Adjugate Montante method Excel: minverse( arraya ) Scilab commands: inv( A ), A^-1, 1/A, (See examples of above methods in MN examples file.) *Solving a linear system (finding the unknown variables vector) Gauss elimination method (with backward substitution) Montante method Excel: mmult( minverse( arraya ), arrayb) ) Scilab Commands: for entire unknown variable vector inv(a) * B ; A^-1 * B ; 1/A * B ; A \ B for individual unknown variable X i (Cramer s rule) det( A mi ) / det( A ) define a Matrix by listing its elements define a Matrix by using other (smaller and larger) matrices A.Cervantes MN Summary Page 6
Part five: Curve fitting. Least-Squares Regression 17.1 LINEAR REGRESSION (Least-Squares Linear Regression) Fitting a straight line to a set of paired observations: (x1, y1), (x2, y2),..., (xn, yn). Math expression for a straight line: = + + ; where a 0 is the intercept; a 1 is the slope; e is the error or residual Examples of some criteria for best fit that are inadequate for regression: (a) minimize the sum of the residuals, = inadequate for regression since any straight line passing through the midpoint of the connecting line (except a perfectly vertical line) results in a minimum value of Eq. (17.2) equal to zero because the errors cancel. (b) minimize the sum of the absolute values of the residuals, = inadequate for regression since for the four points shown, any straight line falling within the dashed lines will minimize the sum of the absolute values. Thus, this criterion also does not yield a unique best fit. (c) minimizes the maximum error of any individual point. inadequate for regression because it gives undue influence to an outlier, that is, a single point with a large error. The above criteria could work for some particular cases, but NOT for a general case. Rather than this we ll minimize the sum of the squares of the residuals between the measured y and the y calculated with the linear model: = = =,, (17.3) To determine values for a 0 and a 1, Eq. (17.3) is differentiated with respect to each coefficient: = 2 A.Cervantes MN Summary Page 7
= 2[ ] Setting these derivatives equal to zero will result in a minimum Sr. If this is done, the equations can be expressed as cero: 0= 0= Resulting in a set of two simultaneous linear equations with two unknowns (a 0 and a 1) known as normal equations: + = + = That can be solved simultaneously, = (17.6) = (17.7) *Use of Excel Analysis ToolPack for Linear regression 17.1.5 Linearization of not linear equations Equation: Exponential = Power function: = Saturated Growth- Rate: = + To linearize: ln=ln + ln ln=ln + log= log+log 1 = 1 + 1 axis: ln y vs x log y vs log x 1/y vs 1/x Slope: Intercept: 1 A.Cervantes MN Summary Page 8
17.2 Polynomial regression (order 2) Para ajustar a la línea de regresión cuadrática: = + + + se resuelve el siguiente sistema de ecuaciones lineales: + + = + + = (17.19) + + = Nota: todas las sumatorias son para i=1 hasta n Para encontrar la línea de regresión polinomial de grado m de manera similar habría que resolver un sistema de m+1 ecuaciones lineales simultáneas. 17.3 Regresión lineal múltiple Si y es una función lineal de x 1 y x 2 como en: = + + + A.Cervantes MN Summary Page 9
se resuelve el siguiente sistema de ecuaciones lineales: + + = + + = (17.22) + + = sumatorias son para i=1 hasta n Nota: todas las *Use of Excel Analysis ToolPack for Multiple Linear regression A.Cervantes MN Summary Page 10