NUMERICAL METHODS IN ELECTRICAL ENGINEERING

Slides:



Advertisements
Similar presentations
CS-110 Computational Engineering Part 3
Advertisements

Roundoff and truncation errors
Copyright © 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 1 ~ Curve Fitting ~ Least Squares Regression Chapter.
Algebraic, transcendental (i.e., involving trigonometric and exponential functions), ordinary differential equations, or partial differential equations...
MATH 685/ CSI 700/ OR 682 Lecture Notes
SOLVING SYSTEMS OF LINEAR EQUATIONS. Overview A matrix consists of a rectangular array of elements represented by a single symbol (example: [A]). An individual.
Lecture 9: Introduction to Matrix Inversion Gaussian Elimination Sections 2.4, 2.5, 2.6 Sections 2.2.3, 2.3.
ES 240: Scientific and Engineering Computation. InterpolationPolynomial  Definition –a function f(x) that can be written as a finite series of power functions.
Solution of linear system of equations
Chapter 9 Gauss Elimination The Islamic University of Gaza
ECIV 201 Computational Methods for Civil Engineers Richard P. Ray, Ph.D., P.E. Error Analysis.
Chapter 4 Roots of Equations
ECIV 301 Programming & Graphics Numerical Methods for Engineers Lecture 6 Roots of Equations Bracketing Methods.
Curve-Fitting Regression
Revision.
ECIV 301 Programming & Graphics Numerical Methods for Engineers REVIEW III.
Engineering Computation Curve Fitting 1 Curve Fitting By Least-Squares Regression and Spline Interpolation Part 7.
ECIV 520 Structural Analysis II Review of Matrix Algebra.
ECIV 301 Programming & Graphics Numerical Methods for Engineers REVIEW II.
Systems of Linear Equations
CISE-301: Numerical Methods Topic 1: Introduction to Numerical Methods and Taylor Series Lectures 1-4: KFUPM.
NUMERICAL DIFFERENTIATION The derivative of f (x) at x 0 is: An approximation to this is: for small values of h. Forward Difference Formula.
Copyright © 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 1 ~ Linear Algebraic Equations ~ Gauss Elimination Chapter.
Least-Squares Regression
Computational Methods in Physics PHYS 3437 Dr Rob Thacker Dept of Astronomy & Physics (MM-301C)
Ch 8.1 Numerical Methods: The Euler or Tangent Line Method
19.5 Numeric Integration and Differentiation
Wicomico High School Mrs. J. A. Austin AP Calculus 1 AB Third Marking Term.
Solving Non-Linear Equations (Root Finding)
Mathematics for Computer Graphics (Appendix A) Won-Ki Jeong.
Chapter 15 Modeling of Data. Statistics of Data Mean (or average): Variance: Median: a value x j such that half of the data are bigger than it, and half.
Chapter 17 Boundary Value Problems. Standard Form of Two-Point Boundary Value Problem In total, there are n 1 +n 2 =N boundary conditions.
CISE-301: Numerical Methods Topic 1: Introduction to Numerical Methods and Taylor Series Lectures 1-4: KFUPM CISE301_Topic1.
CISE301_Topic11 CISE-301: Numerical Methods Topic 1: Introduction to Numerical Methods and Taylor Series Lectures 1-4:
EE 3561_Unit_1(c)Al-Dhaifallah EE 3561 : - Computational Methods in Electrical Engineering Unit 1: Introduction to Computational Methods and Taylor.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 1 Part 4 Curve Fitting.
MECN 3500 Inter - Bayamon Lecture 7 Numerical Methods for Engineering MECN 3500 Professor: Dr. Omar E. Meza Castillo
Lecture 22 - Exam 2 Review CVEN 302 July 29, 2002.
Review Taylor Series and Error Analysis Roots of Equations
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
Chapter 3 Solution of Algebraic Equations 1 ChE 401: Computational Techniques for Chemical Engineers Fall 2009/2010 DRAFT SLIDES.
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.
MA/CS 375 Fall MA/CS 375 Fall 2002 Lecture 31.
Curve-Fitting Regression
MECN 3500 Inter - Bayamon Lecture 3 Numerical Methods for Engineering MECN 3500 Professor: Dr. Omar E. Meza Castillo
Chapter 3 Roots of Equations. Objectives Understanding what roots problems are and where they occur in engineering and science Knowing how to determine.
Quadrature rules 1Michael Sokolov / Numerical Methods for Chemical Engineers / Numerical Quadrature Michael Sokolov ETH Zurich, Institut für Chemie- und.
Numerical Methods.
CHAPTER 3 NUMERICAL METHODS
MECN 3500 Inter - Bayamon Lecture 9 Numerical Methods for Engineering MECN 3500 Professor: Dr. Omar E. Meza Castillo
Solving Non-Linear Equations (Root Finding)
Today’s class Numerical differentiation Roots of equation Bracketing methods Numerical Methods, Lecture 4 1 Prof. Jinbo Bi CSE, UConn.
Chapter 9 Gauss Elimination The Islamic University of Gaza
Curve Fitting Pertemuan 10 Matakuliah: S0262-Analisis Numerik Tahun: 2010.
Lecture 6 - Single Variable Problems & Systems of Equations CVEN 302 June 14, 2002.
Numerical Methods and Optimization C o u r s e 1 By Bharat R Chaudhari.
Assignment 1: due 1/19/16 Estimate all of the zero of x3-x2-2x+1 graphically. Write a MatLab code for Newton’s method. Use your code to refine the graphical.
1 M 277 (60 h) Mathematics for Computer Sciences Bibliography  Discrete Mathematics and its applications, Kenneth H. Rosen  Numerical Analysis, Richard.
NUMERICAL ANALYSIS I. Introduction Numerical analysis is concerned with the process by which mathematical problems are solved by the operations.
NUMERICAL DIFFERENTIATION Forward Difference Formula
Advanced Engineering Mathematics 6th Edition, Concise Edition
FE Exam Tutorial
Class Notes 18: Numerical Methods (1/2)
MATH 2140 Numerical Methods
Numerical Analysis Lecture 45.
MATH-321 In One Slide MATH-321 & MATLAB Command.
Assignment 1: due 1/17/19 Estimate all of the zero of x3-x2-2x+1 graphically. Write a MatLab code for Newton’s method. Use your code to refine the graphical.
CISE-301: Numerical Methods Topic 1: Introduction to Numerical Methods and Taylor Series Lectures 1-4: KFUPM CISE301_Topic1.
Presentation transcript:

NUMERICAL METHODS IN ELECTRICAL ENGINEERING CEE203 NUMERICAL METHODS IN ELECTRICAL ENGINEERING Assist. Prof. Dr. Çağatay ULUIŞIK culuisik@dogus.edu.tr

OUTLINE Introducing MatLab Fundamental Terms, Basic Definitions Solving Nonlinear Equations – Root Finding Solving Systems of Linear Equations Taylor Series Numerical Differentiation Numerical Integration Curve Fitting and Interpolation Ordinary Differential Equations

INTRODUCING MATLAB Vectors, Arrays and Matrices Assign a value to a variable (observe the effect of the semicolon): Creating a row vector of size (14) Creating a column vector of size (41) Creating an array of size (19) using the colon sign (:)

INTRODUCING MATLAB Creating an array of size (19) using the for loop : Creating a matrix of size (33) : Creating a matrix of size (33) using 2 for loops :

BASIC MATRIX OPERATIONS IN MATLAB

GRAPHIC UTILITIES OF MATLAB

GRAPHIC UTILITIES OF MATLAB

COMPLEX NUMBERS IN MATLAB Defining a Complex Number : Conjugate : Magnitude : Angle in Radians : Angle in Degrees : Addition : Subtraction : Multiplication : Division :

LOADING DATA FROM A FILE AND SAVING DATA TO A FILE

STATISTICS IN MATLAB Generation of Uniformly Distributed Random Numbers : Generation of Uniformly Distributed Random Integers : Mean Value : Variance : Standard Deviation :

INTRODUCING MATLAB Roots of a Polynom : Symbolic Integration : Numeric Integration : clc : To clear the command window clear all : To clear all the variables in memory

FORMAT OF DATA round floor ceil Round towards nearest integer Round towards minus infinity ceil Round towards plus infinity

EXAMPLES OF MATLAB SCRIPTS Example 1 : Calculating of the sum of integers from 1 to a user-specifed value n a) using a formula b)using iterations Example 2 : Creating and Calling a function

EXAMPLES OF MATLAB SCRIPTS Example 3 : Error of the first n terms in the Taylor Series of the function ex a) Calculating the error for a given n value b) Calculating the minimum required number of terms n for a given error. a) b)

FUNDAMENTAL TERMS Accuracy: Closeness of agreement between a measured / computed value and a true value. Measurement accuracy: the ability of an instrument to measure the true value to within some stated error specifications. Numerical accuracy: the degree to which the numerical solution to the approximate physical problem approximates the exact solution to the approximate physical problem.

MEASUREMENT ACCURACY Comparison of a measured value with the real value Meas. Value Meas. frequency Mean Value interval Accuracy = (%) True val. – Meas. val True value True value ?

ERROR It is the difference between a measured or calculated value of a quantity and its exact value. Systematic error plagues experiments or calculations caused by negative factors. For example, a DC voltage component, which unintentionally is present, e.g., because of a failure on the blockage capacitor, is a systematic error. These can be removed once understood/discovered via controls and calibration. Random error is an error which is always present, but varies unpredictably in size and direction. They are related to the scatter in the data obtained under fixed conditions which determine the repeatability (precision) of the measurement and follow well-behaved statistical rules.

ERROR Absolute error: It is an error that is expressed in physical units. It is the absolute value of the difference between the measured value and the true value (or the average value if the true value is not known) of a quantity. Relative error: An error expressed as a fraction of the absolute error to the true (or average) value of a quantity. It is always given as a percentage.

ERROR A number is represented with a finite (fixed) number of digits called word length. Precision of a measurement or the accuracy of a computation bounds the number of significant digits. All non-zero digits beyond the number of significant digits at the right of a number are removed in one of two ways; truncation or round-off. For example, 53.0534 has 6 significant digits. If it is going to be represented only by 4 significant digits both truncation and round-off processes yield 53.05. On the other hand, if the number of significant digits will be 3, then truncation and round-off processes yield, 53.0 and 53.1, respectively.

ERROR CALCULATIONS A measurement/calculation result should be given as (a  a), which means the value may be anything between (a - a) and (a + a). For example, if the measured speed is 98  3 km/hr, then the real value may be anything between 95 and 101 km/hr. Total error is the sum of individual errors for the arithmetic combination of two measurements. Total relative error is the sum of individual relative errors for the mulitlicative combination of two measurements.

ERROR CALCULATIONS A parameter (say “A”) is going to be estimated / calculated from two measurements (say “B” and “C”), with the measurement errors of “b” and “c”, respectively. If A = B + C then total error will be If A = B  C then total error will be

ERROR CALCULATIONS In general, the total (propagated) error is obtained from these two properties as For a multi-variable function, the total error is calculated from

UNCERTAINTY Uncertainty is a range that is likely to contain the true value of a quantity being measured or calculated. Uncertainty can be expressed in absolute or relative terms. Modeling uncertainty is defined as the potential deficiency due to a lack of information. Modeling error is the recognizable deficiency not due to a lack of information but due to the approximations and simplifications made there. Measurement error is the difference between the measured and true values, while measurement uncertainty is an estimate of the error in a measurement.

UNCERTAINTY Modeling and simulation uncertainties occur during the phase of Conceptual modeling of the physical system Mathematical modeling of the conceptual model Discretization Computer modeling of the mathematical model Computer modeling of the discrete model Numerical solution Numerical uncertainties occur during computations due to round-off, turncation, non-convergence, artificial dissipations, etc.

ERROR / UNCERTAINTY Digital Voltmeter Accuracy: (0.25 % Reading + 2 digit) Meaning; multiply the value you read on the multimeter by 0.25 % (i.e., by 0.0025) . This is called scaling error. Add 2 times the value of the least significant digit to the result. This is called quantization error. Example: You read 15.00 V from a 20 V scale. Measurement error : 0.0025  15.00 = 0.0375 V Quantization error : 2  0.01 = 0.02 V Total error :  0.0375 + 0.02 =  0.0575 V

MODELING ERROR Truncation error is also defined for mathematical modeling. For example, Taylor’s expansion or a Fourier-series representation are used to replace a function in terms of an infinite summation. Taking only a given number of low-order terms, and neglecting the rest of the higher-order terms, introduces a truncation error. For example, the Taylor expansion of the exponent function: yields (for n=3)

2Pt 3Pt + O(∆x) + O(∆x2) FDTD MODELING ERROR Derivative f(x) Mathematical definition Finite difference approximation 2Pt + O(∆x) 3Pt + O(∆x2)

SOLVING NONLINEAR EQUATIONS Fixed Point Iteration Method Bisection Method Secant Method Newton-Raphson Method MatLab Built-in Functions

FIXED POINT ITERATION METHOD The equation f(x)=0 is rewritten in the form : The intersection point of the graphs of the functions y=x and y=g(x) is the solution and is called the fixed point . The numerical solution is obtained by an iterative process. First a xi value near the fixed point is chosen and substituted into g(x). The solution is substituted back into g(x). So the iteration formula is given by:

FIXED POINT ITERATION METHOD g(x1) x g(x2) x3= g(x3) x4= g(x4) x5= g(x5) x6= x7= g(x6) g(x7) g(x) y=x

FIXED POINT ITERATION METHOD Example: Convergence Test: i xi 1 6.0000 2 0.8571 3 3.2308 4 1.4182 5 2.4812 6 1.7235 7 2.2030 8 1.8732 9 2.0882 10 1.9429 11 2.0388 y=x g(x)=6/(x+1)

FIXED POINT ITERATION METHOD Choosing the appropriate iteration function g(x) The fixed point iteration method converges if in the neighborhood of the fixed point the derivative of g(x) has an absolute value smaller than 1. (also called Lipschitz continious) Example: The plot of the function shows that the equation has a solution between 1 and 2. The actual solution is at x=1.5050 . f(x)=xe0.5x+1.2x-5 x

FIXED POINT ITERATION METHOD Case A Case B Case C Divergent Convergent i xi 1 1.0000 2 2.7927 3 -5.2367 4 4.4849 5 -31.0262 6 4.1667 7 -23.7195 8 4.1668 9 -23.7223 10 11 i xi 1 1.0000 2 1.7552 3 1.3869 4 1.5622 5 1.4776 6 1.5182 7 1.4987 8 1.5080 9 1.5035 10 1.5057 11 1.5046 i xi 1 1.0000 2 2.3048 3 0.7057 4 2.9183 5 0.3482 6 3.8500 7 0.0554 8 4.7986 9 -0.0688 10 5.2606 11 -0.0946

BISECTION METHOD STEP 1: Choose two points a and b such that a solution exists between them : f(a) f(b) < 0 STEP 2: Find c=(a+b)/2 STEP 3: Determine whether the true solution is between a and c or between c and b. Then select the subinterval that contains the true solution If f(a) f(c) < 0 , solution is between a and c. anew=a, bnew=c If f(b) f(c) < 0 , solution is between c and b. anew=c, bnew=b STEP 4: Repeat steps 2 and 3 until (b-a) is less than a specified tolerance

BISECTION METHOD f(a) f(b) f(a)  f(b) < 0 True Root f(a) f(b) f(b) c=(a+b) /2 True Root f(a) f(b) f(b) f(a) f(b) f(a)

BISECTION METHOD a b c f(c) abs(b-a) 5.0000 12.0000 8.5000 18.7500 7.0000 6.7500 -2.6875 3.5000 7.6250 7.2656 1.7500 7.1875 2.0977 0.8750 6.9688 -0.3428 0.4375 7.0781 0.8655 0.2188 7.0234 0.2584 0.1094 6.9961 -0.0430 0.0547 7.0098 0.1075 0.0273 7.0029 0.0322 0.0137 6.9995 -0.0054 0.0068 7.0012 0.0134 0.0034 7.0004 0.0040 0.0017

NEWTON RAPSON METHOD f(x1) f(x) f(x2) Exact Root x x5 x4 x3 x2 x1 Slope: f’(x1) f(x2) Exact Root Slope: f’(x2) Slope: f’(x3) x x5 x4 x3 x2 x1 Slope: f’(x4)

NEWTON RAPSON METHOD xi f(xi) xi -xi-1 6.00000000 31.00000000 4.60238918 11.14583002 1.3976 3.27847524 3.85164919 1.3239 2.13314198 1.19335902 1.1453 1.34820293 0.27297398 0.7849 1.03883431 0.02728345 0.3094 1.00051801 0.00035912 0.0383 1.00000009 0.00000006 0.0005

SECANT METHOD f(x1) f(x) f(x2) f(x3) Exact Root f(x4) f(x5) x x6 x5 x4

SECANT METHOD xi f(xi) xi -xi-1 6.00000000 31.00000000 5.00000000 15.00000000 1.0000 4.06250000 7.35419026 0.9375 3.16075727 3.47149501 0.9017 2.35451439 1.55711029 0.8062 1.69873759 0.62308391 0.6558 1.26127246 0.19853535 0.4375 1.05669682 0.04008167 0.2046 1.00494836 0.00343583 0.0517 1.00009654 0.00006692 0.0049 1.00000017 0.00000011 0.0001

MATLAB BUILT-IN FUNCTIONS The roots(p) command finds the roots of a polynomial, whose coefficients are defined in the row vector p. The following MatLab script find the roots of the polynom P(x)=x3-3x2-13x+15 >> coef=[1 -3 -13 15]; >> xi=roots(coef) xi = 5.0000 -3.0000 1.0000 The fzero(‘function’,x0) command finds the roots of the ‘function’ near x0. The following MatLab script find the roots of the function f(x)=x3-3x2-13x+15 >> x=fzero('x^3-3*x^2-13*x+15',7) x = 5 >> x=fzero('x^3-3*x^2-13*x+15',3) x = 1

SYSTEMS OF LINEAR EQUATIONS Gauss Elimination Method Gauss-Jordan Elimination Method LU Decomposition Method

GAUSS ELIMINATION METHOD Backward Substitution :

LU DECOMPOSITION METHOD A is the coefficients matrix. U is an upper triangular matrix and is obtained at the end of the Gauss elimination procedure. L is a lower triangular matrix which has all 1’s on the diagonal and the elements below the diagonal are the multipliers mij that multiply the pivot equation when it is used to eliminate the elements below the pivot coefficient at the Gauss elimination procedure. L is a lower triangular matrix and y is obtained from Ly=b using forward substitution. U is an upper triangular matrix and x is obtained from Ux=y using backward substitution.

LU DECOMPOSITION METHOD Forward Substitution : Backward Substitution :

GAUSS-JORDAN ELIMINATION METHOD

GAUSS-JORDAN ELIMINATION METHOD

GAUSS-JORDAN ELIMINATION METHOD MATLAB SCRIPT A=[2 -1 1 -4; 4 2 -5 22; 5 2 -1 15]; [n,col]=size(A); %------------------------------------------------------------------- for i=1:n A(i,:)=A(i,:)/A(i,i); disp('A ='); disp(A); pause; for k=i+1:n dd=A(k,i); A(k,:)=A(k,:)-dd*A(i,:); A pause; end for i=n:-1:2 for k=i-1:-1:1 x=A(:,col); disp(' The unknowns are :'); disp(x); rref(A) % MatLab built-in function

TAYLOR SERIES Taylor Series : Maclaurin Series : Example :

TAYLOR SERIES

NUMERICAL DIFFERENTIATION Two-Point Forward Difference Method Two-Point Backward Difference Method Two-Point Central Difference Method Three-Point Forward Difference Method Three-Point Backward Difference Method

NUMERICAL DIFFERENTIATION xi xi+1 f(xi) h f(xi+1) True derivative Approximated f(x) True derivative xi xi-1 f(xi) h f(xi-1) True derivative Approximated f(x) Forward Difference Backward Difference Forward Difference: xi+1 xi-1 f(xi+1) 2h f(xi-1) Approximated derivative f(x) Central Difference Backward Difference: Central Difference:

NUMERICAL DIFFERENTIATION Truncation Error: 2 Point Forward Difference: 2 Point Backward Difference: 2 Point Central Difference: 3 Point Forward Difference: 3 Point Backward Difference:

NUMERICAL DIFFERENTIATION Example : For f(x)=ln(x) estimate the value of f’(0.2) taking h=0.01. xi-2 0.18 xi-1 0.19 xi 0.2 xi+1 0.21 xi+2 0.22 f(xi-2) ln(0.18) f(xi-1) ln(0.19) f(xi) ln(0.2) f(xi+1) ln(0.21) f(xi+2) ln(0.22) Method Used f’(0.2) Abs. Error 2 Point Forward Difference 4.879 0.121 2 Point Backward Difference 5.1293 0.1293 2 Point Central Difference 5.0042 0.0042 3 Point Forward Difference 4.9925 0.0075 3 Point Backward Difference 4.9906 0.0094

NUMERICAL DIFFERENTIATION h f’(0.8) Abs. Error 0.7500 0.8819 0.3681 0.5000 0.9710 0.2790 0.4000 1.0137 0.2363 0.3000 1.0615 0.1885 0.2000 1.1157 0.1343 0.1000 1.1778 0.0722 0.0500 1.2125 0.0375 0.0100 1.2423 0.0077 0.0050 1.2461 0.0039 0.0010 1.2492 0.0008 0.0005 1.2496 0.0004 0.0001 1.2499 h f’(0.8) Abs. Error 0.7500 3.6968 2.4468 0.5000 1.9617 0.7117 0.4000 1.7329 0.4829 0.3000 1.5667 0.3167 0.2000 1.4384 0.1884 0.1000 1.3353 0.0853 0.0500 1.2908 0.0408 0.0100 1.2579 0.0079 0.0050 1.2539 0.0039 0.0010 1.2508 0.0008 0.0005 1.2504 0.0004 0.0001 1.2501 2 Point Forward Difference: 2 Point Backward Difference: h f’(0.8) Abs. Error 0.7500 2.2893 1.0393 0.5000 1.4663 0.2163 0.4000 1.3733 0.1233 0.3000 1.3141 0.0641 0.2000 1.2771 0.0271 0.1000 1.2566 0.0066 0.0500 1.2516 0.0016 0.0100 1.2501 6.51e-005 0.0050 1.2500 1.63e-005 0.0010 6.51e-007 0.0005 1.63e-007 0.0001 6.51e-009 h f’(0.8) Abs. Error 0.7500 1.0597 0.1903 0.5000 1.1311 0.1189 0.4000 1.1609 0.0891 0.3000 1.1903 0.0597 0.2000 1.2178 0.0322 0.1000 1.2399 0.0101 0.0500 1.2472 0.0028 0.0100 1.2499 0.0001 0.0050 1.2499679 3.21e-005 0.0010 1.2499987 1.298e-006 0.0005 1.24999967 3.25e-007 1.249999987 1.30e-008 2 Point Central Difference: 3 Point Forward Difference:

NUMERICAL DIFFERENTIATION

NUMERICAL DIFFERENTIATION h f’(1.5) Abs. Error 1.0000 0.8000 0.2000 0.5000 0.1000 0.9000 0.0500 0.9500 0.0100 0.9900 0.0050 0.9950 0.0010 0.9990

NUMERICAL INTEGRATION Rectangle Methods Midpoint Method Trapezoidal Method Simpsons Methods Simpsons 1/3 Method Simpsons 3/8 Method

NUMERICAL INTEGRATION 1. Rectangle Method a f(a) b f(b) f(x) a f(a) b f(b) f(x) 2. Rectangle Method Midpoint Method Trapezoidal Method a f(a) b f(b) f(x) a f(a) b f(b) f(x)

NUMERICAL INTEGRATION 1. Rectangle Method f(x) f(x2) f(x1) I1 I2 I3 Ii Ii+1 IN-1 IN h h h h h h h   x1 a x2 x3 xi xi+1 xN-1 xN xN+1 b

NUMERICAL INTEGRATION 2. Rectangle Method x1 a x2  xi xi+1 xN-1 xN xN+1 b x3 f(x1) I1 I2 I3 Ii Ii+1 IN-1 IN h f(x2) f(x)

NUMERICAL INTEGRATION Midpoint Method x1 a x2  xi xi+1 xN-1 xN xN+1 b x3 I1 I2 I3 Ii Ii+1 IN-1 IN h f(x) (x1+x2) 2 (x2+x3) 2

NUMERICAL INTEGRATION Trapezoidal Method x1 a x2  xi xi+1 xN-1 xN xN+1 b x3 f(x1) I1 I2 I3 Ii Ii+1 IN-1 IN h f(x2) f(x)

NUMERICAL INTEGRATION Simpson 1/3 Method A second order polynomial g(x) is used to approximate the integrand f(x) f(x) g(x) f(x1) h/2=k h/2=k x1 a x2 x3 b

NUMERICAL INTEGRATION Simpson 3/8 Method A third order polynomial g(x) is used to approximate the integrand f(x) f(x) g(x) f(x1) h/3=k h/3=k h/3=k x1 a x2 x3 x4 b

NUMERICAL INTEGRATION

NUMERICAL INTEGRATION 1. Rectangular Method h Num Int. Abs. Error Rel. Error % 5 1115 325 22.569 2.5 1277.5 162.5 11.285 2 1310 130 9.0278 1 1375 65 4.5139 0.5 1407.5 32.5 2.2569 0.1 1433.5 6.5 0.45139 0.05 1436.8 3.25 0.22569 0.01 1439.3 0.65 0.045139 0.005 1439.7 0.325 0.022569 0.001 1439.9 0.065 0.0045139 0.0005 1440 0.0325 0.0022569 0.0001 0.0065 0.00045139 2. Rectangular Method h Num Int. Abs. Error Rel. Error % 5 1765 325 22.569 2.5 1602.5 162.5 11.285 2 1570 130 9.0278 1 1505 65 4.5139 0.5 1472.5 32.5 2.2569 0.1 1446.5 6.5 0.45139 0.05 1443.3 3.25 0.22569 0.01 1440.6 0.65 0.045139 0.005 1440.3 0.325 0.022569 0.001 1440.1 0.065 0.0045139 0.0005 1440 0.0325 0.0022569 0.0001 0.0065 0.00045139

NUMERICAL INTEGRATION 1. Rect. Method 2. Rect. Method h Num Int. Abs. Error 8 400 10.667 720 330.67 4 352 37.333 512 122.67 2 360 29.333 440 50.667 1 372 17.333 412 22.667 0.5 380 9.3333 0.1 387.36 1.9733 391.36 2.0267 0.05 388.34 0.99333 390.34 1.0067 0.01 389.13 0.19973 389.53 0.20027 0.005 389.23 0.099933 389.43 0.10007 0.001 389.31 0.019997 389.35 0.020003 0.0005 389.32 0.009999 389.34 0.010001 0.0001 389.33 0.002 Midpoint Method h Num Int. Abs. Error 8 304 85.333 4 368 21.333 2 384 5.3333 1 388 1.3333 0.5 389 0.33333 0.1 389.32 0.013333 0.05 389.33 0.0033333 0.01 0.00013333 0.005 3.3333e-005 0.001 1.3333e-006 0.0005 3.3333e-007 0.0001 1.3332e-008 Trapezoidal Method h Num Int. Abs. Error 8 560 170.67 4 432 42.667 2 400 10.667 1 392 2.6667 0.5 390 0.66667 0.1 389.36 0.026667 0.05 389.34 0.0066667 0.01 389.33 0.00026667 0.005 6.6667e-005 0.001 2.6667e-006 0.0005 6.6667e-007 0.0001 2.6663e-008

NUMERICAL INTEGRATION (h=0.1) Numerical Integration Absolute Error 1. Rectangle Method 387.36 1.9733 2. Rectangle Method 391.36 2.0267 Midpoint Method 389.32 0.013333 Trapezoidal Method 389.36 0.026667 Simpsons 1/3 Method 389.33 5.6843e-014 Simpsons 3/8 Method

CURVE FITTING WITH A LINEAR FUNCTION f(x)=a1x+a0 (xi ,yi) yi rN yN ri (xN ,yN) (x1 ,y1) y1 r1 r2 y2 (x2 ,y2) x1 x2 xi xN A linear function f(x)=a1x+a0 is used to best fit the given data points (xi ,yi). A residual ri at point (xi , yi) is the difference between the value yi of the data point and the value of the function f(xi) used to approximate the data points : ri= yi -f(xi)

CURVE FITTING WITH A LINEAR FUNCTION The overall error E is defined as the sum of the squares of the residuals : Linear least-squares regression : The coefficients a1 and a0 of the linear function f(x)=a1x+a0 are determined such that the error E has the smallest possible value. E is minimum if: The coefficients a1 and a0 are found as:

CURVE FITTING WITH A LINEAR FUNCTION Example : Use linear least-squares regression to determine the coefficients a1 and a0 in the function f(x)=a1x+a0 that best fits the data given below. x 1 2 3 4 5 6 7 8 9 10 y 9.2 13 14.7 19.7 21.8 22.8 29.1 30.2 32.2

CURVE FITTING WITH A LINEAR FUNCTION yi f(xi) ri= yi -f(xi) (ri)2 6.0000 6.5145 -0.5145 0.2648 9.2000 9.4824 -0.2824 0.0798 13.0000 12.4503 0.5497 0.3022 14.7000 15.4182 -0.7182 0.5158 19.7000 18.3861 1.3139 1.7264 21.8000 21.3539 0.4461 0.1990 22.8000 24.3218 -1.5218 2.3159 29.1000 27.2897 1.8103 3.2772 30.2000 30.2576 -0.0576 0.0033 32.2000 33.2255 -1.0255 1.0516 E= 9.736 f(x)=2.9679x+3.5467 +

CURVE FITTING WITH A LINEAR FUNCTION Example : Use linear least-squares regression to determine the coefficients a1 and a0 in the function f(x)=a1x+a0 that best fits the data given below. x 2 5 6 8 9 13 15 y 7 10 11 12 14

CURVE FITTING WITH A LINEAR FUNCTION f(x)=0.64x+5.6968 yi f(xi) ri= yi -f(xi) (ri)2 7.0000 6.9769 0.0231 0.0005 8.0000 8.8970 -0.8970 0.8046 10.0000 9.5370 0.4630 0.2143 11.0000 10.8171 0.1829 0.0334 12.0000 11.4572 0.5428 0.2947 14.0000 14.0174 -0.0174 0.0003 15.0000 15.2975 -0.2975 0.0885 E= 1.4363 +

CURVE FITTING WITH A LINEAR FUNCTION Example : Use linear least-squares regression to determine the coefficients a1 and a0 in the function f(x)=a1x+a0 that best fits the data given below. Use f(x) to determine the interpolated value n for x=4 and the extrapolated value m for x= -8. x -8 -7 -5 -1 2 4 5 6 y m 15 12 n -9

CURVE FITTING WITH A LINEAR FUNCTION m f(x)=1.7786x+ 2.8571 n Interpolation : Using the data points for estimating the expexted values between the known points. Extrapolation : Using the data points for estimating the expexted values beyond the known points.

LAGRANGE POLYNOMIALS For n+1 data points (x0 , y0), (x1 , y1), (x2 , y2), ….. (xk , yk), ….. (xn , yn) a unique polynomial of order n can be found, which passes through these n data points. A Lagrange interpolating polynomial Pn(x) that passes through n points is defined as :

LAGRANGE POLYNOMIALS MATLAB SCRIPT Example : Find the Lagrange interpolation polynomial that passes through the points : x 2 2.5 4 y 0.5 0.4 0.25 MATLAB SCRIPT x=[2 2.5 4]; y=[0.5 0.4 0.25]; polyfit(x,y,2)

LAGRANGE POLYNOMIALS x 2 2.5 4 y 0.5 0.4 0.25 The Lagrange interpolation polynomial that passes through the points :

LAGRANGE POLYNOMIALS Example : Find the Lagrange interpolation polynomial that passes through the points : x 1 2 y -1 7

LAGRANGE POLYNOMIALS x 1 2 y -1 7 The Lagrange interpolation polynomial that passes through the points :

LAGRANGE POLYNOMIALS Example : Find the Lagrange interpolation polynomial that passes through the points : x 1 3 4 y 15

LAGRANGE POLYNOMIALS x 1 3 4 y 15 The Lagrange interpolation polynomial that passes through the points :

LAGRANGE POLYNOMIALS Example : Find the Lagrange interpolation polynomial that passes through the points : x 3 4 5 y 8 -4 18

LAGRANGE POLYNOMIALS x 3 4 5 y 8 -4 18 The Lagrange interpolation polynomial that passes through the points :

ORDINARY DIFFERENTIAL EQUATIONS A differential equation is an equation that contains derivatives of an unknown function. A differential equation that has one independent variable is called an ordinary differential equation (ODE). If an ODE involves only first derivatives of the dependent variable (y) with respect to the independent variable (x), it is a first – order ordinary differential equation. A first –order ODE is linear, if it is a linear function of y and dy/dx.

EULER’S METHOD yi+1 yi h xi xi+1 Numerical Solution Exact Solution Slope =f(xi, yi) y(x) Numerical Solution Exact Solution

EULER’S METHOD Example : Use Euler’s method to solve the Ordinary Differential Equation below from x=0 to x=1 with the initial conditions x=0 and y=2. (Take h=0.2) Compute the errors in each step for the exact solution y=3ex-x-1

EULER’S METHOD h=0.25 h=0.1 h=0.05 h=0.2 xi yi (Euler) (Exact) Abs. Error 2.0000 0.2500 2.5000 2.6021 0.1021 0.5000 3.1875 3.4462 0.2587 0.7500 4.1094 4.6010 0.4916 1.0000 5.3242 6.1548 0.8306 xi yi (Euler) (Exact) Abs. Error 2.0000 0.1000 2.2000 2.2155 0.0155 0.2000 2.4300 2.4642 0.0342 0.3000 2.6930 2.7496 0.0566 0.4000 2.9923 3.0755 0.0832 0.5000 3.3315 3.4462 0.1146 0.6000 3.7147 3.8664 0.1517 0.7000 4.1462 4.3413 0.1951 0.8000 4.6308 4.8766 0.2459 0.9000 5.1738 5.4788 0.3050 1.0000 5.7812 6.1548 0.3736 xi yi (Euler) (Exact) Abs. Error 2.0000 0.0500 2.1000 2.1038 0.0038 0.1000 2.2075 2.2155 0.0080 0.1500 2.3229 2.3355 0.0126 0.2000 2.4465 2.4642 0.0177 0.2500 2.5788 2.6021 0.0232 0.3000 2.7203 2.7496 0.0293 0.3500 2.8713 2.9072 0.0359 0.4000 3.0324 3.0755 0.0431 0.4500 3.2040 3.2549 0.0510 0.5000 3.3867 3.4462 0.0595 0.5500 3.5810 3.6498 0.0687 0.6000 3.7876 3.8664 0.0788 0.6500 4.0069 4.0966 0.0897 0.7000 4.2398 4.3413 0.1015 0.7500 4.4868 4.6010 0.1142 0.8000 4.7486 4.8766 0.1280 0.8500 5.0261 5.1689 0.1429 0.9000 5.3199 5.4788 0.1590 0.9500 5.6309 5.8071 0.1763 1.0000 5.9599 6.1548 0.1950 h=0.2 xi yi (Euler) (Exact) Abs. Error 2.0000 0.2000 2.4000 2.4642 0.0642 0.4000 2.9200 3.0755 0.1555 0.6000 3.5840 3.8664 0.2824 0.8000 4.4208 4.8766 0.4558 1.0000 5.4650 6.1548 0.6899

EULER’S METHOD

EULER’S METHOD Example : Use Euler’s method to solve the Ordinary Differential Equation below from x=0 to x=1.8 with the initial conditions x=0 and y=1. (Take h=0.6) Compute the errors in each step for the exact solution.

EULER’S METHOD h=0.6 h=0.1 h=0.3 xi yi (Euler) (Exact) Abs. Error xi 1.0000 0.6000 1.1628 0.1628 1.2000 1.2304 1.3856 0.1552 1.8000 1.0795 0.1869 0.8926 xi yi (Euler) (Exact) Abs. Error 1.0000 0.1000 1.0050 0.0050 0.2000 1.0099 1.0198 0.0099 0.3000 1.0293 1.0440 0.0147 0.4000 1.0575 1.0767 0.0192 0.5000 1.0934 1.1169 0.0235 0.6000 1.1355 1.1628 0.0272 0.7000 1.1821 1.2124 0.0303 0.8000 1.2305 1.2629 0.0323 0.9000 1.2778 1.3107 0.0329 1.3199 1.3513 0.0314 1.1000 1.3518 1.3787 0.0269 1.2000 1.3675 1.3856 0.0181 1.3000 1.3587 1.3620 0.0033 1.4000 1.3157 1.2955 0.0201 1.5000 1.2255 1.1698 0.0557 1.6000 1.0718 0.9634 0.1084 1.7000 0.8337 0.6481 0.1855 1.8000 0.4841 0.1869 0.2972 h=0.3 xi yi (Euler) (Exact) Abs. Error 1.0000 0.3000 1.0440 0.0440 0.6000 1.0819 1.1628 0.0809 0.9000 1.2118 1.3107 0.0989 1.2000 1.3203 1.3856 0.0652 1.5000 1.2773 1.1698 0.1075 1.8000 0.8395 0.1869 0.6526

EULER’S METHOD