CISE301 Numerical Methods Topic 1 Introduction to Numerical

  • Slides: 63
Download presentation
CISE-301: Numerical Methods Topic 1: Introduction to Numerical Methods and Taylor Series Lectures 1

CISE-301: Numerical Methods Topic 1: Introduction to Numerical Methods and Taylor Series Lectures 1 -4: KFUPM 1

Lecture 1 Introduction to Numerical Methods p p p What are NUMERICAL METHODS? Why

Lecture 1 Introduction to Numerical Methods p p p What are NUMERICAL METHODS? Why do we need them? Topics covered in CISE 301. Reading Assignment: Pages 3 -10 of textbook 2

Numerical Methods: Algorithms that are used to obtain numerical solutions of a mathematical problem.

Numerical Methods: Algorithms that are used to obtain numerical solutions of a mathematical problem. Why do we need them? 1. No analytical solution exists, 2. An analytical solution is difficult to obtain or not practical. 3

What do we need? Basic Needs in the Numerical Methods: n Practical: Can be

What do we need? Basic Needs in the Numerical Methods: n Practical: Can be computed in a reasonable amount of time. n Accurate: Good approximate to the true value, p Information about the approximation error (Bounds, error order, … ). p 4

Outlines of the Course p p p Taylor Theorem Number Representation Solution of nonlinear

Outlines of the Course p p p Taylor Theorem Number Representation Solution of nonlinear Equations Interpolation Numerical Differentiation Numerical Integration p p Solution of linear Equations Least Squares curve fitting Solution of ordinary differential equations Solution of Partial differential equations 5

Solution of Nonlinear Equations p Some simple equations can be solved analytically: p Many

Solution of Nonlinear Equations p Some simple equations can be solved analytically: p Many other equations have no analytical solution: 6

Methods for Solving Nonlinear Equations o Bisection Method o Newton-Raphson Method o Secant Method

Methods for Solving Nonlinear Equations o Bisection Method o Newton-Raphson Method o Secant Method 7

Solution of Systems of Linear Equations 8

Solution of Systems of Linear Equations 8

Cramer’s Rule is Not Practical 9

Cramer’s Rule is Not Practical 9

Methods for Solving Systems of Linear Equations o Naive Gaussian Elimination o Gaussian Elimination

Methods for Solving Systems of Linear Equations o Naive Gaussian Elimination o Gaussian Elimination with Scaled Partial Pivoting o Algorithm for Tri-diagonal Equations 10

Curve Fitting p Given a set of data: p Select a curve that best

Curve Fitting p Given a set of data: p Select a curve that best fits the data. One choice is to find the curve so that the sum of the square of the error is minimized. 11

Interpolation p Given a set of data: p Find a polynomial P(x) whose graph

Interpolation p Given a set of data: p Find a polynomial P(x) whose graph passes through all tabulated points. 12

Methods for Curve Fitting o Least Squares o o o Linear Regression Nonlinear Least

Methods for Curve Fitting o Least Squares o o o Linear Regression Nonlinear Least Squares Problems Interpolation o o Newton Polynomial Interpolation Lagrange Interpolation 13

Integration p Some functions can be integrated analytically: 14

Integration p Some functions can be integrated analytically: 14

Methods for Numerical Integration o Upper and Lower Sums o Trapezoid Method o Romberg

Methods for Numerical Integration o Upper and Lower Sums o Trapezoid Method o Romberg Method o Gauss Quadrature 15

Solution of Ordinary Differential Equations 16

Solution of Ordinary Differential Equations 16

Solution of Partial Differential Equations are more difficult to solve than ordinary differential equations:

Solution of Partial Differential Equations are more difficult to solve than ordinary differential equations: 17

Summary p p Numerical Methods: Algorithms that are used to obtain numerical solution of

Summary p p Numerical Methods: Algorithms that are used to obtain numerical solution of a mathematical problem. We need them when No analytical solution exists or it is difficult to obtain it. Topics Covered in the Course p p p Solution of Nonlinear Equations Solution of Linear Equations Curve Fitting n n p p Least Squares Interpolation Numerical Integration Numerical Differentiation Solution of Ordinary Differential Equations Solution of Partial Differential Equations 18

Lecture 2 Number Representation and Accuracy p p p Number Representation Normalized Floating Point

Lecture 2 Number Representation and Accuracy p p p Number Representation Normalized Floating Point Representation Significant Digits Accuracy and Precision Rounding and Chopping Reading Assignment: Chapter 3 19

Representing Real Numbers p You are familiar with the decimal system: p Decimal System:

Representing Real Numbers p You are familiar with the decimal system: p Decimal System: p Standard Representations: Base = 10 , Digits (0, 1, …, 9) 20

Normalized Floating Point Representation p Normalized Floating Point Representation: p No integral part, p

Normalized Floating Point Representation p Normalized Floating Point Representation: p No integral part, p Advantage: Efficient in representing very small or very large numbers. 21

Calculator Example p Suppose you want to compute: 3. 578 * 2. 139 using

Calculator Example p Suppose you want to compute: 3. 578 * 2. 139 using a calculator with two-digit fractions 3. 57 * 2. 13 = 7. 60 True answer: 7. 653342 22

Binary System p Binary System: Base = 2, Digits {0, 1} 23

Binary System p Binary System: Base = 2, Digits {0, 1} 23

7 -Bit Representation (sign: 1 bit, mantissa: 3 bits, exponent: 3 bits) 24

7 -Bit Representation (sign: 1 bit, mantissa: 3 bits, exponent: 3 bits) 24

Fact p Numbers that have a finite expansion in one numbering system may have

Fact p Numbers that have a finite expansion in one numbering system may have an infinite expansion in another numbering system: p You can never represent 0. 1 exactly in any computer. 25

Representation Hypothetical Machine (real computers use ≥ 23 bit mantissa) Mantissa: 3 bits Exponent:

Representation Hypothetical Machine (real computers use ≥ 23 bit mantissa) Mantissa: 3 bits Exponent: 2 bits Sign: 1 bit Possible positive machine numbers: . 25. 3125. 375. 4375. 5. 625. 75. 875 1 1. 25 1. 75 26

Representation Gap near zero 27

Representation Gap near zero 27

Remarks p Numbers that can be exactly represented are called machine numbers. p Difference

Remarks p Numbers that can be exactly represented are called machine numbers. p Difference between machine numbers is not uniform p Sum of machine numbers is not necessarily a machine number: 0. 25 +. 3125 = 0. 5625 (not a machine number) 28

Significant Digits p Significant digits are those digits that can be used with confidence.

Significant Digits p Significant digits are those digits that can be used with confidence. 29

Significant Digits - Example 48. 9 30

Significant Digits - Example 48. 9 30

Accuracy and Precision p Accuracy is related to the closeness to the true value.

Accuracy and Precision p Accuracy is related to the closeness to the true value. p Precision is related to the closeness to other estimated values. 31

32

32

Rounding and Chopping p Rounding: Replace the number by the nearest machine number. p

Rounding and Chopping p Rounding: Replace the number by the nearest machine number. p Chopping: Throw all extra digits. 33

Rounding and Chopping Example 34

Rounding and Chopping Example 34

Error Definitions – True Error Can be computed if the true value is known:

Error Definitions – True Error Can be computed if the true value is known: 35

Error Definitions – Estimated Error When the true value is not known: 36

Error Definitions – Estimated Error When the true value is not known: 36

Notation We say that the estimate is correct to n decimal digits if: We

Notation We say that the estimate is correct to n decimal digits if: We say that the estimate is correct to n decimal digits rounded if: 37

Summary p Number Representation Numbers that have a finite expansion in one numbering system

Summary p Number Representation Numbers that have a finite expansion in one numbering system may have an infinite expansion in another numbering system. p Normalized Floating Point Representation n Efficient in representing very small or very large numbers, Difference between machine numbers is not uniform, Representation error depends on the number of bits used in the mantissa. 38

Lectures 3 -4 Taylor Theorem p p p Motivation Taylor Theorem Examples Reading assignment:

Lectures 3 -4 Taylor Theorem p p p Motivation Taylor Theorem Examples Reading assignment: Chapter 4 39

Motivation p We can easily compute expressions like: b a 0. 6 40

Motivation p We can easily compute expressions like: b a 0. 6 40

Taylor Series 41

Taylor Series 41

Taylor Series – Example 1 42

Taylor Series – Example 1 42

Taylor Series Example 1 43

Taylor Series Example 1 43

Taylor Series – Example 2 44

Taylor Series – Example 2 44

45

45

Convergence of Taylor Series (Observations, Example 1) p The Taylor series converges fast (few

Convergence of Taylor Series (Observations, Example 1) p The Taylor series converges fast (few terms are needed) when x is near the point of expansion. If |x-c| is large then more terms are needed to get a good approximation. 46

Taylor Series – Example 3 47

Taylor Series – Example 3 47

Example 3 – Remarks p Can we apply Taylor series for x>1? ? p

Example 3 – Remarks p Can we apply Taylor series for x>1? ? p How many terms are needed to get a good approximation? ? ? These questions will be answered using Taylor’s Theorem. 48

Taylor’s Theorem (n+1) terms Truncated Taylor Series Remainder 49

Taylor’s Theorem (n+1) terms Truncated Taylor Series Remainder 49

Taylor’s Theorem 50

Taylor’s Theorem 50

Error Term 51

Error Term 51

Error Term – Example 4 52

Error Term – Example 4 52

Alternative form of Taylor’s Theorem 53

Alternative form of Taylor’s Theorem 53

Taylor’s Theorem – Alternative forms 54

Taylor’s Theorem – Alternative forms 54

Mean Value Theorem 55

Mean Value Theorem 55

Alternating Series Theorem 56

Alternating Series Theorem 56

Alternating Series – Example 5 57

Alternating Series – Example 5 57

Example 6 58

Example 6 58

Example 6 – Taylor Series 59

Example 6 – Taylor Series 59

Example 6 – Error Term 60

Example 6 – Error Term 60

Remark p In this course, all angles are assumed to be in radian unless

Remark p In this course, all angles are assumed to be in radian unless you are told otherwise. 61

Maclaurin Series p Find Maclaurin series expansion of cos (x). p Maclaurin series is

Maclaurin Series p Find Maclaurin series expansion of cos (x). p Maclaurin series is a special case of Taylor series with the center of expansion c = 0. 62

Maclaurin Series – Example 7 63

Maclaurin Series – Example 7 63