mecn 3500 inter - bayamon lecture 3 numerical methods for engineering mecn 3500 professor: dr. omar...

29
MECN 3500 MECN 3500 Inter - Bayamon Inter - Bayamon Lecture Lecture 3 3 Numerical Methods for Engineering Numerical Methods for Engineering MECN 3500 MECN 3500 Professor: Dr. Omar E. Meza Castillo Professor: Dr. Omar E. Meza Castillo [email protected] http://www.bc.inter.edu/facultad/omeza Department of Mechanical Engineering Department of Mechanical Engineering Inter American University of Puerto Rico Inter American University of Puerto Rico Bayamon Campus Bayamon Campus

Upload: marcus-perkins

Post on 03-Jan-2016

222 views

Category:

Documents


1 download

TRANSCRIPT

MEC

N 3

500 I

nte

r -

Bayam

on

MEC

N 3

500 I

nte

r -

Bayam

on

LectureLecture

33Numerical Methods for EngineeringNumerical Methods for Engineering

MECN 3500 MECN 3500

Professor: Dr. Omar E. Meza CastilloProfessor: Dr. Omar E. Meza [email protected]

http://www.bc.inter.edu/facultad/omeza

Department of Mechanical EngineeringDepartment of Mechanical Engineering

Inter American University of Puerto RicoInter American University of Puerto Rico

Bayamon CampusBayamon Campus

Lecture 3Lecture 3MEC

N 3

500 I

nte

r -

Bayam

on

MEC

N 3

500 I

nte

r -

Bayam

on

22

Tentative Lectures ScheduleTentative Lectures Schedule

TopicTopic LectureLecture

Mathematical Modeling and Engineering Problem SolvingMathematical Modeling and Engineering Problem Solving 11

Introduction to MatlabIntroduction to Matlab 22

Numerical ErrorNumerical Error 33

Root FindingRoot Finding 33

System of Linear EquationsSystem of Linear Equations

Least Square Curve FittingLeast Square Curve Fitting

Polynomial Interpolation Polynomial Interpolation

Numerical IntegrationNumerical Integration

Ordinary Differential Equations Ordinary Differential Equations

Lecture 3Lecture 3MEC

N 3

500 I

nte

r -

Bayam

on

MEC

N 3

500 I

nte

r -

Bayam

on

Accuracy and PrecisionAccuracy and Precision

Approximations and Round-Approximations and Round-Off ErrorsOff Errors

33

Lecture 3Lecture 3MEC

N 3

500 I

nte

r -

Bayam

on

MEC

N 3

500 I

nte

r -

Bayam

on

To understand the concept of error and its To understand the concept of error and its importance to the effective use of importance to the effective use of numerical methods.numerical methods.

44

Course ObjectivesCourse Objectives

Lecture 3Lecture 3MEC

N 3

500 I

nte

r -

Bayam

on

MEC

N 3

500 I

nte

r -

Bayam

on

For many engineering problems, we cannot obtain For many engineering problems, we cannot obtain analytical solutions.analytical solutions.

Numerical methods yield approximate results, Numerical methods yield approximate results, results that are close to the exact analytical results that are close to the exact analytical solution. We cannot exactly compute the errors solution. We cannot exactly compute the errors associated with numerical methods.associated with numerical methods. Only rarely given data are exact, since they originate Only rarely given data are exact, since they originate

from measurements. Therefore there is probably from measurements. Therefore there is probably error in the input information.error in the input information.

Algorithm itself usually introduces errors as well, Algorithm itself usually introduces errors as well, e.g., unavoidable round-offs, etc …e.g., unavoidable round-offs, etc …

The output information will then contain error from The output information will then contain error from both of these sourcesboth of these sources..

How confident we are in our approximate result?How confident we are in our approximate result? The question is “The question is “how much error is present in our how much error is present in our

calculation and is it tolerable?”calculation and is it tolerable?”

55

IntroductionIntroduction

Lecture 3Lecture 3MEC

N 3

500 I

nte

r -

Bayam

on

MEC

N 3

500 I

nte

r -

Bayam

on Accuracy and PrecisionAccuracy and Precision

Accuracy.Accuracy. How close is a computed or How close is a computed or measured value to the true valuemeasured value to the true value

Precision (or Precision (or reproducibilityreproducibility).). How close is How close is a computed or measured value to a computed or measured value to previously computed or measured values.previously computed or measured values.

InaccuracyInaccuracy (or (or biasbias).). A systematic A systematic deviation from the actual value.deviation from the actual value.

ImprecisionImprecision (or (or uncertaintyuncertainty).). Magnitude Magnitude of scatter.of scatter.

66

Lecture 3Lecture 3MEC

N 3

500 I

nte

r -

Bayam

on

MEC

N 3

500 I

nte

r -

Bayam

on Accuracy and PrecisionAccuracy and Precision

77

Lecture 3Lecture 3MEC

N 3

500 I

nte

r -

Bayam

on

MEC

N 3

500 I

nte

r -

Bayam

on Significant FiguresSignificant Figures

Number of significant figures indicates precision. Number of significant figures indicates precision. Significant digits of a number are those that can Significant digits of a number are those that can be be usedused with with confidence, confidence, e.g.,e.g., the number of the number of certain digits plus one estimated digit.certain digits plus one estimated digit.

53,853,80000 How many significant figures?How many significant figures?

5.38 x 105.38 x 1044 335.380 x 105.380 x 1044 445.3800 x 105.3800 x 1044 55

Zeros are sometimes used to locate the decimal Zeros are sometimes used to locate the decimal point not significant figures.point not significant figures.

0.000017530.00001753 440.00017530.0001753 440.0017530.001753 44

88

Lecture 3Lecture 3MEC

N 3

500 I

nte

r -

Bayam

on

MEC

N 3

500 I

nte

r -

Bayam

on Error DefinitionsError Definitions

value trueerror true error relative fractional True

99

%100value trueerror true error, relative percent True t

True Value = Approximation + ErrorTrue Value = Approximation + Error

EEtt = True value – Approximation (+/-) = True value – Approximation (+/-)

True error

Lecture 3Lecture 3MEC

N 3

500 I

nte

r -

Bayam

on

MEC

N 3

500 I

nte

r -

Bayam

on

1010

Lecture 3Lecture 3MEC

N 3

500 I

nte

r -

Bayam

on

MEC

N 3

500 I

nte

r -

Bayam

on Error DefinitionsError Definitions

Example 3.1: Calculation of ErrorsExample 3.1: Calculation of Errors Problem Statement: Problem Statement: Suppose that you have Suppose that you have

the task of measuring the lengths of a the task of measuring the lengths of a bridge and a rivet and come up with 9999 bridge and a rivet and come up with 9999 and 9 cm, respectively. If the true values and 9 cm, respectively. If the true values are 10000 and 10 cm, respectively, are 10000 and 10 cm, respectively, compute (a) the true error and (b) the true compute (a) the true error and (b) the true percent relative error for each case.percent relative error for each case.

Solution:Solution:

The error for measuring the bridgeThe error for measuring the bridge

EEtt=10000-9999=1cm=10000-9999=1cm

And for the rivet it isAnd for the rivet it is

EEtt=10-9=1cm=10-9=1cm

1111

Lecture 3Lecture 3MEC

N 3

500 I

nte

r -

Bayam

on

MEC

N 3

500 I

nte

r -

Bayam

on Error DefinitionsError Definitions

The percent relative error for the bridge The percent relative error for the bridge isis

And for the rivet it isAnd for the rivet it is

Thus, although both measurements have Thus, although both measurements have an error of 1 cm, the relative error for the an error of 1 cm, the relative error for the rivet is much greater.rivet is much greater.

1212

%01.0%10010000

1t

%10%10010

1t

Lecture 3Lecture 3MEC

N 3

500 I

nte

r -

Bayam

on

MEC

N 3

500 I

nte

r -

Bayam

on Error DefinitionsError Definitions

For numerical methods, the true For numerical methods, the true value will be known only when we deal value will be known only when we deal with functions that can be solved with functions that can be solved analytically (simple systems). In real world analytically (simple systems). In real world applications, we usually not know the applications, we usually not know the answer a priori. Thenanswer a priori. Then

Iterative approachIterative approach, , example Newton’s example Newton’s methodmethod

1313

%100ionApproximaterror eApproximat a

%100ionapproximat Current

ionapproximat Previous - ionapproximat Current a

(+ / -)

Lecture 3Lecture 3MEC

N 3

500 I

nte

r -

Bayam

on

MEC

N 3

500 I

nte

r -

Bayam

on Error DefinitionsError Definitions

Use absolute value.Use absolute value. Computations are repeated until stopping Computations are repeated until stopping

criterion is satisfied.criterion is satisfied.

If the following Scarborough criterion is metIf the following Scarborough criterion is met

you can be sure that the result is correct to at you can be sure that the result is correct to at least least n significantn significant figures. figures.

1414

sa Pre-specified % tolerance

based on the knowledge of your solution

)%n)-(2s 10 (0.5

Lecture 3Lecture 3MEC

N 3

500 I

nte

r -

Bayam

on

MEC

N 3

500 I

nte

r -

Bayam

on

1515

Lecture 3Lecture 3MEC

N 3

500 I

nte

r -

Bayam

on

MEC

N 3

500 I

nte

r -

Bayam

on Error DefinitionsError Definitions

Example 3.2: Error Estimates for Iterative Example 3.2: Error Estimates for Iterative MethodsMethods Problem Statement: Problem Statement: In mathematics, In mathematics,

functions can often be represented by functions can often be represented by infinite series. For example, the infinite series. For example, the exponential function can be computed exponential function can be computed using Maclaurin Series Expansion. Starting using Maclaurin Series Expansion. Starting with the simplest version, ewith the simplest version, exx=1, add terms =1, add terms one at a time to estimate eone at a time to estimate e0.50.5. Note that the . Note that the true value etrue value e0.50.5= 1.648721 = 1.648721

Solution:Solution:

1616

!nx...

!3x

2x1e

n32

x x

Lecture 3Lecture 3MEC

N 3

500 I

nte

r -

Bayam

on

MEC

N 3

500 I

nte

r -

Bayam

on Error DefinitionsError Definitions

First to determine the error criterion First to determine the error criterion that ensures a result is correct to at least that ensures a result is correct to at least three significant figures:three significant figures:

First term First term

The True error: Et= 1.648721 – 1= 0.648721The True error: Et= 1.648721 – 1= 0.648721

1717

%05.0)% 3)-(2s 10 (0.5

1ex

%3.39%100t 1.648721

1-1.648721

Lecture 3Lecture 3MEC

N 3

500 I

nte

r -

Bayam

on

MEC

N 3

500 I

nte

r -

Bayam

on Error DefinitionsError Definitions

Second term Second term

The True error: Et= 1.648721 – 1.5= The True error: Et= 1.648721 – 1.5= 0.1487210.148721

1818

5.15.01x1ex

%02.9%100t 1.648721

1.5-1.648721

%3.33%100 1.5

1-1.5 a

Lecture 3Lecture 3MEC

N 3

500 I

nte

r -

Bayam

on

MEC

N 3

500 I

nte

r -

Bayam

on Error DefinitionsError Definitions

The entire computation can be summarized asThe entire computation can be summarized as

Thus, after the six terms are included, the Thus, after the six terms are included, the approximate error falls below approximate error falls below εεss=0.05% and =0.05% and the computation is terminatedthe computation is terminated

1919

Terms Results εt(%) εa(%)

1 1 39.3

2 1.5 9.02 33.3

3 1.625 1.44 7.69

4 1.645833333 0.175 1.27

5 1.648437500 0.0172 0.158

6 1.648697917 0.00142 0.0158

Lecture 3Lecture 3MEC

N 3

500 I

nte

r -

Bayam

on

MEC

N 3

500 I

nte

r -

Bayam

on Round-Off ErrorRound-Off Error

Round-off errors originate from the fact Round-off errors originate from the fact that computers retain only a fixed number that computers retain only a fixed number of significant figures during a calculation. of significant figures during a calculation. Number such as pi, e, or sqrt(7) cannot be Number such as pi, e, or sqrt(7) cannot be expressed by a fixed number of significant expressed by a fixed number of significant figures. Therefore they cannot be figures. Therefore they cannot be represented exactly by the computer.represented exactly by the computer.

Computer use a base-2 representation, Computer use a base-2 representation, they can not precisely represent certain they can not precisely represent certain exact base-10 numbers.exact base-10 numbers.

The discrepancy introduced by this The discrepancy introduced by this omission of significant figures is called omission of significant figures is called round-off errorround-off error..

2020

Lecture 3Lecture 3MEC

N 3

500 I

nte

r -

Bayam

on

MEC

N 3

500 I

nte

r -

Bayam

on Computer Representation of NumbersComputer Representation of Numbers

Numerical round-off error is related to the Numerical round-off error is related to the manner in which number are stored.manner in which number are stored.

““Word” is the fundamental unit of Word” is the fundamental unit of information storage. It consist of a string information storage. It consist of a string of binary digits or bits.of binary digits or bits.

Number Systems:Number Systems: Decimal-Base-10 System: 0, 1, 2, 3, 4, 5, Decimal-Base-10 System: 0, 1, 2, 3, 4, 5,

6, 7, 8, 96, 7, 8, 9 Binary-Base-2 System: 0, 1Binary-Base-2 System: 0, 1

2121

Lecture 3Lecture 3MEC

N 3

500 I

nte

r -

Bayam

on

MEC

N 3

500 I

nte

r -

Bayam

on Computer Representation of NumbersComputer Representation of Numbers

2222

Lecture 3Lecture 3MEC

N 3

500 I

nte

r -

Bayam

on

MEC

N 3

500 I

nte

r -

Bayam

on Computer Representation of NumbersComputer Representation of Numbers

Integer Representation: Integer Representation: The previous The previous slides show how to represent 10-based slides show how to represent 10-based numbers to binary form.numbers to binary form.

The most straightforward approach to The most straightforward approach to represent integers on a computer is called represent integers on a computer is called signed magnitude methodsigned magnitude method. It employs the . It employs the first bit of a word to indicate the sign, with first bit of a word to indicate the sign, with o for positive and a 1 for negative.o for positive and a 1 for negative.

Representation of the decimal integer -173 Representation of the decimal integer -173 on a 16-bit computer. on a 16-bit computer.

2323

Lecture 3Lecture 3MEC

N 3

500 I

nte

r -

Bayam

on

MEC

N 3

500 I

nte

r -

Bayam

on Computer Representation of NumbersComputer Representation of Numbers

Floating-Point Representation: Floating-Point Representation: Fractional Fractional quantities are typically represented in quantities are typically represented in computer using floating-point form. In this computer using floating-point form. In this approach, the number is expressed as a approach, the number is expressed as a fractional part, called a fractional part, called a mantissa or mantissa or significandsignificand, and a integer part, called an , and a integer part, called an exponent or characteristicexponent or characteristic, as in, as in

2424

em.b exponent

Base of the number system used

mantissa

Integer part

Lecture 3Lecture 3MEC

N 3

500 I

nte

r -

Bayam

on

MEC

N 3

500 I

nte

r -

Bayam

on Computer Representation of NumbersComputer Representation of Numbers

156.78156.780.15678x100.15678x103 3 in a floating point in a floating point base-10 system.base-10 system.

2525

Lecture 3Lecture 3MEC

N 3

500 I

nte

r -

Bayam

on

MEC

N 3

500 I

nte

r -

Bayam

on Computer Representation of NumbersComputer Representation of Numbers

Normalized to remove the leading zeroes. Normalized to remove the leading zeroes. Multiply the mantissa by 10 and lower the Multiply the mantissa by 10 and lower the exponent by 1.exponent by 1.

0.2940.29411 x 10 x 10-1-1

2626

121100294.0

029411765.0341

0

m

Suppose only 4 decimal places to be stored

Additional significant figure is retained

Lecture 3Lecture 3MEC

N 3

500 I

nte

r -

Bayam

on

MEC

N 3

500 I

nte

r -

Bayam

on Computer Representation of NumbersComputer Representation of Numbers

ThereforeThereforefor a base-10 system for a base-10 system 0.1 0.1 ≤m<1≤m<1for a base-2 systemfor a base-2 system 0.5 0.5 ≤m<1≤m<1

Floating point representation allows both Floating point representation allows both fractions and very large numbers to be fractions and very large numbers to be expressed on the computer. However,expressed on the computer. However, Floating point numbers take up more room.Floating point numbers take up more room. Take longer to process than integer numbers.Take longer to process than integer numbers. Round-off errors are introduced because mantissa Round-off errors are introduced because mantissa

holds only a finite number of significant figures.holds only a finite number of significant figures.

2727

basetheb

mantisam

,1mb

1

Lecture 3Lecture 3MEC

N 3

500 I

nte

r -

Bayam

on

MEC

N 3

500 I

nte

r -

Bayam

on ChoppingChopping

Example:Example: ππ=3.14159265358 to be stored on a base-10 =3.14159265358 to be stored on a base-10

system carrying 7 significant digits.system carrying 7 significant digits. π π =3.141592=3.141592 chopping error chopping error

eett=0.00000065=0.00000065 π π =3.141593=3.141593 rounded error rounded error

eett=0.00000035=0.00000035

Some machines use chopping, becauseSome machines use chopping, because rounding adds to the computational rounding adds to the computational overhead. Since number of significant figures overhead. Since number of significant figures is large enough, resulting chopping error is is large enough, resulting chopping error is negligible.negligible.

2828

Lecture 3Lecture 3MEC

N 3

500 I

nte

r -

Bayam

on

MEC

N 3

500 I

nte

r -

Bayam

on

Homework2 Homework2 www.bc.inter.edu/facultad/omeza

Omar E. Meza Castillo Ph.D.Omar E. Meza Castillo Ph.D.

2929