45
Numerical Methods Intro to Numerical Methods & Intro to Matlab Programming By M Jamil Khan

Numerical Methods Intro to Numerical Methods & Intro to Matlab Programming By M Jamil Khan

Embed Size (px)

Citation preview

Page 1: Numerical Methods Intro to Numerical Methods & Intro to Matlab Programming By M Jamil Khan

Numerical Methods

Intro to Numerical Methods

&

Intro to Matlab Programming

By M Jamil Khan

Page 2: Numerical Methods Intro to Numerical Methods & Intro to Matlab Programming By M Jamil Khan

Numerical Methods

What are numerical

methods and why should

you study them?

Page 3: Numerical Methods Intro to Numerical Methods & Intro to Matlab Programming By M Jamil Khan

Numerical Methods

“Numerical Methods are techniques by which

mathematical Problems are formulated so that they can be

solved with arithmetic and logical operations. Because

digital computers excel at performing such operations,

numerical methods are sometimes referred as computer

mathematics”.

Page 4: Numerical Methods Intro to Numerical Methods & Intro to Matlab Programming By M Jamil Khan

Numerical Methods

In pre computer era , the time and effort of implementing

such calculations seriously limited their practical use.

However, with the advent of fast, inexpensive digital

computers, the role of numerical methods in engineering

and scientific problem solving has exploded.

Page 5: Numerical Methods Intro to Numerical Methods & Intro to Matlab Programming By M Jamil Khan

Numerical Methods

Numerical methods figure so prominently in, much of our

work, I believe that numerical methods should be a part of

every engineer's and scientist's basic education. Just as we

all must have solid foundation in the other areas of

mathematics and science, we should also have a

fundamental understanding of numerical methods. In

particular, we should have a solid appreciation of both

their capabilities and their limitations.

Why?

Page 6: Numerical Methods Intro to Numerical Methods & Intro to Matlab Programming By M Jamil Khan

Numerical Methods

Beyond contributing to your overall education. .there are

several additional reasons why you should study

numerical methods: 1

Page 7: Numerical Methods Intro to Numerical Methods & Intro to Matlab Programming By M Jamil Khan

1Numerical Methods

Numerical methods greatly expand the types of , problems

you can address. They are capable of handling large

systems of equations nonlinearities, and complicated

geometries that are not uncommon in engineering and

science and that are often impossible to solve analytically

with standard calculus. As such they greatly enhance your

problem-solving skills.2

Page 8: Numerical Methods Intro to Numerical Methods & Intro to Matlab Programming By M Jamil Khan

2Numerical Methods

Numerical methods allow you to use "canned“ software

with insight. During your career, you will invariably have

occasion to use commercially available pre-packaged

computer programs that involve numerical methods. The

intelligent use of these programs is greatly enhanced by an

understanding of the basic theory underlying the methods.

In the absence of such understanding you will be left to

treat such packages as “black boxes“ with little critical

insight into their inner workings or the validity of the

results they produce.

3

Page 9: Numerical Methods Intro to Numerical Methods & Intro to Matlab Programming By M Jamil Khan

3Numerical Methods

Many problems cannot be approached using canned

programs. If you are conversant with numerical methods,

and are adept at computer programming, you can design

your own programs to solve problems without having to

buy or commission expensive software.4

Page 10: Numerical Methods Intro to Numerical Methods & Intro to Matlab Programming By M Jamil Khan

4Numerical Methods

Numerical methods are an efficient vehicle for learning to

use computers. Because numerical methods are expressly

designed for computer implementation, they are ideal for

illustrating the computer's powers and limitations. When

you successfully implement numerical methods on a

computer, and then apply them to solve otherwise

intractable problems, you will be provided with a dramatic

demonstration of how computer can serve our professional

development. At the same time, you will also learn to

acknowledge and control the errors of approximation that

are part and parcel of large-scale numerical calculations.

5

Page 11: Numerical Methods Intro to Numerical Methods & Intro to Matlab Programming By M Jamil Khan

5Numerical Methods

Numerical methods provide a vehicle for you to reinforce

your understanding of mathematics. Because one function

of numerical methods is to reduce higher mathematics to

basic arithmetic operations. they get at the "nuts and bolts"

of some otherwise obscure topics. Enhanced

understanding and insight can result from this alternative

perspective.

Page 12: Numerical Methods Intro to Numerical Methods & Intro to Matlab Programming By M Jamil Khan

Books

Reference Books

• A first Course in Numerical Analysis with C++ by Dr. Saeed

Akhtar Bhatti, 4th Edition.

• Applied Numerical Methods using Matlab by Won Young Yang.

• Applied Numerical Methods with Matlab for Engineers and

Scientists by Steven C. Chapra, 2nd Edition.

Page 13: Numerical Methods Intro to Numerical Methods & Intro to Matlab Programming By M Jamil Khan

Grading Policy

Unannounced Quizzes 20%

Lab Assignments 20%

(Late and Missed Submissions are Not Applicable)

Mid Exam 20%

Final Exam 40%

+ Attendance

+ Discipline

Page 14: Numerical Methods Intro to Numerical Methods & Intro to Matlab Programming By M Jamil Khan

Computer Usage

You should be able to write a computer

code in a programming language you

know such as MATLAB or C.

Page 15: Numerical Methods Intro to Numerical Methods & Intro to Matlab Programming By M Jamil Khan

Some Useful Links

http://web.uettaxila.edu.pk/CMS/FA2011/teNMTbs/

http://www.library.nu

http://www.google.com

http://www.codeproject.com

http://numericalmethods.eng.usf.edu

http://math.gmu.edu/introtomatlab.htm

http://www.mathworks.com

Page 16: Numerical Methods Intro to Numerical Methods & Intro to Matlab Programming By M Jamil Khan

Feedback Request

Please mail questions and constructive comments to

[email protected]

Your feedback will be most appreciated

On style, contents, detail, examples, clarity, conceptual

problems, exercises, missing information, depth, etc.

Local course support website

http://web.uettaxila.edu.pk/CMS/SP2011/teNMTbs/

Page 17: Numerical Methods Intro to Numerical Methods & Intro to Matlab Programming By M Jamil Khan

Course Objective

This course will emphasize the development of numerical

algorithms to provide solutions to common problems

formulated in science and engineering. The primary

objective of the course is to develop the basic

understanding of the construction of numerical algorithms,

and perhaps more importantly, the applicability and limits

of their appropriate use.

Page 18: Numerical Methods Intro to Numerical Methods & Intro to Matlab Programming By M Jamil Khan

Course Outline

Introduction to Numerical Methods

Introduction to Matlab Programming

Error Analysis

Finite Differences

Interpolation

Numerical Differentiation

Page 19: Numerical Methods Intro to Numerical Methods & Intro to Matlab Programming By M Jamil Khan

Course Outline

Numerical Integration

Ordinary Differential Equations

Non Linear Equations

Linear System of Equations

Page 20: Numerical Methods Intro to Numerical Methods & Intro to Matlab Programming By M Jamil Khan

Today Objectives

The primary objective of today’s discussion is to provide

you with a concrete idea of what numerical methods are

and how they relate to engineering and scientific problem

solving. Specific objectives and topics covered are

• Learning how mathematical models can be formulated

on the basis of scientific principles t o simulate the

behavior of a simple physical system.

• Understanding how numerical methods afford a means

to generate solutions in a manner that can be

implemented on a digital computer.

Page 21: Numerical Methods Intro to Numerical Methods & Intro to Matlab Programming By M Jamil Khan

Today Objectives

• Understanding the different types of conservation laws

that lie beneath the models used in the various

engineering disciplines and appreciating the difference

between steady-state and dynamic solutions of these

models.

• Learning about the different types of numerical

methods we will cover in this course.

Page 22: Numerical Methods Intro to Numerical Methods & Intro to Matlab Programming By M Jamil Khan

A Simple Mathematical Model

A mathematical model can be broadly defined as a

formulation or equation that expresses the essential

features of a physical system or process in

mathematical terms.

Models can be represented by a functional relationship

between dependent variables, independent variables,

parameters, and forcing functions.

Page 23: Numerical Methods Intro to Numerical Methods & Intro to Matlab Programming By M Jamil Khan

Model Function

Dependent variable - a characteristic that usually

reflects the behavior or state of the system

Independent variables - dimensions, such as time and

space, along which the system’s behavior is being

determined.

Dependentvariable f

independentvariables , parameters,

forcingfunctions

Page 24: Numerical Methods Intro to Numerical Methods & Intro to Matlab Programming By M Jamil Khan

Model Function

Parameters - constants reflective of the system’s

properties or composition

Forcing functions - external influences acting upon the

system

Page 25: Numerical Methods Intro to Numerical Methods & Intro to Matlab Programming By M Jamil Khan

Model Function ExampleAssuming a bungee jumper is in mid-flight, an

analytical model for the jumper’s velocity,

accounting for drag, is

Dependent variable - velocity v

Independent variables - time t

Parameters - mass m, drag coefficient cd

Forcing function - gravitational acceleration g

v t gm

cd

tanhgcd

mt

Page 26: Numerical Methods Intro to Numerical Methods & Intro to Matlab Programming By M Jamil Khan

Model Results

Using a computer (or a calculator), the model can be used to generate a

graphical representation of the system. For example, the graph below

represents the velocity of a 68.1 kg jumper, assuming a drag

coefficient of 0.25 kg/m

Page 27: Numerical Methods Intro to Numerical Methods & Intro to Matlab Programming By M Jamil Khan

Numerical Modeling

Some system models will be given as implicit functions or as differential

equations - these can be solved either using analytical methods or

numerical methods.

Example - the bungee jumper velocity equation from before is the

analytical solution to the differential equation

where the change in velocity is determined by the gravitational forces

acting on the jumper versus the drag force.

dv

dtg

cd

mv2

Page 28: Numerical Methods Intro to Numerical Methods & Intro to Matlab Programming By M Jamil Khan

Numerical Methods

To solve the problem using a numerical method, note that the time rate

of change of velocity can be approximated as:

dv

dt

v

t

v ti1 v ti ti1 ti

Page 29: Numerical Methods Intro to Numerical Methods & Intro to Matlab Programming By M Jamil Khan

Numerical Results

The efficiency and accuracy of numerical methods will

depend upon how the method is applied. Applying the

previous method in 2 s intervals yields:

Page 30: Numerical Methods Intro to Numerical Methods & Intro to Matlab Programming By M Jamil Khan

Analytical and Numerical Solutions:

Numerical methods are techniques by which

mathematical problems are formulated so that they can be

solved with arithmetic and logical operations.

Numerical Analytical

approximate exact

more intuitive less intuitive

easily coded not so easy

easy to get not so easy

Page 31: Numerical Methods Intro to Numerical Methods & Intro to Matlab Programming By M Jamil Khan

Bases for Numerical Models

Basic Needs in the Numerical Methods: Practical:

Can be computed in a reasonable amount of time.

Accurate: Good approximate to the true value, Information about the approximation error (Bounds,

error order,… ).

Page 32: Numerical Methods Intro to Numerical Methods & Intro to Matlab Programming By M Jamil Khan

Solution of Nonlinear Equations

Some simple equations can be solved analytically:

Many other equations have no analytical solution:

31

)1(2

)3)(1(444solution Analytic

034

2

2

xandx

roots

xx

solution analytic No052 29

xex

xx

Page 33: Numerical Methods Intro to Numerical Methods & Intro to Matlab Programming By M Jamil Khan

Methods for Solving Nonlinear Equations

o Bisection Method

o Newton-Raphson Method

o Secant Method

Page 34: Numerical Methods Intro to Numerical Methods & Intro to Matlab Programming By M Jamil Khan

Solution of Systems of Linear Equations

unknowns. 1000in equations 1000

have weif do What to

123,2

523,3

:asit solvecan We

52

3

12

2221

21

21

xx

xxxx

xx

xx

Page 35: Numerical Methods Intro to Numerical Methods & Intro to Matlab Programming By M Jamil Khan

Cramer’s Rule is Not Practical

this.compute toyears 10 than more needscomputer super A

needed. are tionsmultiplica102.3 system, 30by 30 a solve To

tions.multiplica

1)N!1)(N(N need weunknowns, N with equations N solve To

problems. largefor practicalnot is Rule sCramer'But

2

21

11

51

31

,1

21

11

25

13

:system thesolve toused becan Rule sCramer'

20

35

21

xx

Page 36: Numerical Methods Intro to Numerical Methods & Intro to Matlab Programming By M Jamil Khan

Methods for Solving Systems of Linear Equations

o Naive Gaussian Elimination

o Gaussian Elimination with Scaled Partial Pivoting

o Algorithm for Tri-diagonal Equations

Page 37: Numerical Methods Intro to Numerical Methods & Intro to Matlab Programming By M Jamil Khan

Curve Fitting

Given a set of data:

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.

x 0 1 2

y 0.5 10.3 21.3

Page 38: Numerical Methods Intro to Numerical Methods & Intro to Matlab Programming By M Jamil Khan

Interpolation

Given a set of data:

Find a polynomial P(x) whose graph passes through all tabulated points.

xi 0 1 2

yi 0.5 10.3 15.3

tablein the is)( iii xifxPy

Page 39: Numerical Methods Intro to Numerical Methods & Intro to Matlab Programming By M Jamil Khan

Methods for Curve Fitting

o Least Squareso Linear Regressiono Nonlinear Least Squares Problems

o Interpolationo Newton Polynomial Interpolationo Lagrange Interpolation

Page 40: Numerical Methods Intro to Numerical Methods & Intro to Matlab Programming By M Jamil Khan

Integration

Some functions can be integrated analytically:

?

:solutions analytical no have functionsmany But

42

1

2

9

2

1

0

3

1

23

1

2

dxe

xxdx

ax

Page 41: Numerical Methods Intro to Numerical Methods & Intro to Matlab Programming By M Jamil Khan

Methods for Numerical Integration

o Upper and Lower Sums

o Trapezoid Method

o Romberg Method

o Gauss Quadrature

Page 42: Numerical Methods Intro to Numerical Methods & Intro to Matlab Programming By M Jamil Khan

Solution of Ordinary Differential Equations

only. cases special

for available are solutions Analytical *

equations. thesatisfies that function a is

0)0(;1)0(

0)(3)(3)(

:equation aldifferenti theosolution tA

x(t)

xx

txtxtx

Page 43: Numerical Methods Intro to Numerical Methods & Intro to Matlab Programming By M Jamil Khan

Solution of Partial Differential Equations

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

)sin()0,(,0),1(),0(

022

2

2

2

xxututut

u

x

u

Page 44: Numerical Methods Intro to Numerical Methods & Intro to Matlab Programming By M Jamil Khan

Bases for Numerical Models

Conservation laws provide the foundation for many model

functions. Different fields of engineering and science

apply these laws to different paradigms within the field.

Among these laws are:

Conservation of mass

Conservation of momentum

Conservation of charge

Conservation of energy

Page 45: Numerical Methods Intro to Numerical Methods & Intro to Matlab Programming By M Jamil Khan