lec 1 -2 introduction

Upload: arafatasghar

Post on 02-Apr-2018

230 views

Category:

Documents


0 download

TRANSCRIPT

  • 7/27/2019 Lec 1 -2 Introduction

    1/43

    1

    Lecture 1 - Introduction

    Dr. Nasir M Mirza

    Numerical Methods

    Email: [email protected]

  • 7/27/2019 Lec 1 -2 Introduction

    2/43

    2

    Lectures Goals

    General Introduction to Computer Applications inEngineering and Sciences

    Introduction to numerical analysis

    Why you should be able to write and understand

    computer programs for numerical methods?

    Computer languages C & C++ and Matlab aMathematical Laboratory

  • 7/27/2019 Lec 1 -2 Introduction

    3/43

    3

    Books on Numerical Analysis

    Text Books:

    1. Numerical Analysis, By Burden & Faires, Recent

    Edition.

    2. Numerical methods for engineers and scientists by A.C. Bajpai, I.M. Calus and J.A.Fairley;

    Softwares: C++ or Matlab & SIMULINK

  • 7/27/2019 Lec 1 -2 Introduction

    4/43

    4

    Introduction

    Professor: Dr. Nasir M MirzaOffice : 104 BLOCK-A; PIEAS, P.O.

    Nilore, Islamabad, 45650.

    Email: [email protected]

    URL: http://www.pieas.edu.pk

    http://www.pieas.edu.pk/http://www.pieas.edu.pk/
  • 7/27/2019 Lec 1 -2 Introduction

    5/43

  • 7/27/2019 Lec 1 -2 Introduction

    6/43

    6

    Topics

    Matlab or C++ Computer Errors

    Roots f(x) = 0

    Linear Methods

    Nonlinear Methods

    Linear Systems

    LU Decomposition

    Eigenvalue Analysis

    Fitting Data Interpolation

    Curve Fitting

    Numerical Integration

    ODEs

    Initial Value Problems

    Systems of ODEs

    Boundary ValueProblems

  • 7/27/2019 Lec 1 -2 Introduction

    7/43

    7

    Why numerical analysis and methods?

    Integration becomes easy by use of numerical methods;

    When you wish to solve simultaneous linear equations, you needto find inverse of a matrix A. Thou can is is easy when you havethree equations and three unknown. If say you have 50 equationsand fifty unknowns then with help of digital computers andnumerical analysis you can solve this.

    Say you have to solve one equation exp(x)=10 x. it will be verytroublesome or impossible to solve it analytically. However,numerically it is very easy to solve it.

    Complex differential equations can be solved very easily usingnumerical analysis. Event set of coupled differential equations

    can be solved very quickly and easily using numerical methods. When Discrete data is given, one can differentiate and integrate

    using numerical techniques.

  • 7/27/2019 Lec 1 -2 Introduction

    8/43

    8

    What you need for numerical analysis

    A good scientific calculator for numericals. When you wish to solve simultaneous linear equations,

    say 50 equations and fifty unknowns then you will needdigital computers (say a good PC).

    You will also need good knowledge of one computerprogramming language (say C or C++ or MATLAB).

    Good knowledge ofmathematics will also help.

    Aneat software to plot results is also needed.

  • 7/27/2019 Lec 1 -2 Introduction

    9/43

    9

    Applications

    Signal Processing

    CFD (ComputationalFluid Dynamics)

    Structural Analysis

    Finite Element Analysis

    Interpolation

    Optimization

    CAD (Computer Aided-Drafting)

    Data Collection

  • 7/27/2019 Lec 1 -2 Introduction

    10/43

    10

    Numerical Accuracy and Errors

    Whenever calculations are performed there aremany possible sources of errors. These include

    Mistakes made by person carrying out calculations,

    The use of inaccurate formula; The use of inaccurate data (or round-off errors).

    The first type of error should not be there at all.

    The second type is due to chopping off aninfinite series and this error is called truncationerror.

  • 7/27/2019 Lec 1 -2 Introduction

    11/43

    11

    Truncation ErrorsThis type is due to chopping off an infinite series. For example; let us

    approximate the first derivative at a point x = a by following form:

    The accuracy will increase when h is decreased. To show this, consider

    f(x) = exp(2x) ; we also know, df/dx = 2exp(2x)

    For x = 2; exact answer is 109.1963.

    Now u sing above app roxim ate formula, we f ind values

    h

    afhaf

    dx

    dy )()(

    2635.1342.0

    5982.544509.812.0

    )22exp()2.22exp()()( h

    afhafdxdy

    8412.11405.0

    5982.543403.60

    05.0

    )22exp()05.22exp()()(

    h

    afhaf

    dx

    dy

    2906.11001.0

    5982.547011.55

    01.0

    )22exp()01.22exp()()(

    h

    afhaf

    dx

    dy

  • 7/27/2019 Lec 1 -2 Introduction

    12/43

    12

    Roundoff Errors

    When we were computig exp(4) or exp(4.1) we were rounding off theresults. That is how many digits are written after the decimal places or

    significant figures.

    When rounding off one digit:

    if digit lies in the range 0 4 , the previous digit is unchanged.

    if the digit lies in the range 69, the previous digit is increased by

    one.

    For examp le, 7.4727 becomes 7.473

    76.34 becom es 76.34

    15.235 becom es 15.24

    When rounding off two digit:

    if digit lies in the range 0 49 , the previous digit is unchanged.

    if the digit lies in the range 51 99, the previous digit is increased by

    one.

  • 7/27/2019 Lec 1 -2 Introduction

    13/43

    13

    What is Error

    Hence in rounding off 7.4727 becomes 7.473 and error is -0.0003

    76.34 becomes 76.34 and error is 0.000

    15.235 becomes 15.24 and error is -0.005

    18.496 becomes 18.50 introducing error0.004

    17.208 becomes 17.21 introducing error -0.002

    valueeapproximatvalueexact The error, , in any quantity is given by

    18.50 + 17.21 = 35.71 introducing error

    0.006

    18.50 - 17.21 = 1.29 introducing error -0.007

    The individual errors may be positive or negative but when they are

    added or subtracted they may reinforce each other.

  • 7/27/2019 Lec 1 -2 Introduction

    14/43

    14

    Numerical Errors

    Precision Limits

    Stability

    Convergence

    Divergence

    Alaising

    Round-off Errors

    Truncation Errors

    Machine Precision

  • 7/27/2019 Lec 1 -2 Introduction

    15/43

    15

    Example; first rounding

    Let p = 0.54617 and q = 0.54601.

    The exact value of r = p q

    r = 0.54617 0.54601 = 0.00016

    Here subtraction is performed using four-digit arithmetic.

    Rounding p and q to four digits gives

    p* = 0.5462 & q* - 0.5460,

    r* = p* - q* = 0.0002

    25.000016.0

    0002.000016.0*

    r

    rrerrorrelative

  • 7/27/2019 Lec 1 -2 Introduction

    16/43

    16

    Example; now chopping

    Let p = 0.54617 and q = 0.54601.

    The exact value of r = p q

    r = 0.54617 0.54601 = 0.00016

    If chopping is used to obtain the four digits, then the four-digit approximations to p, q, and r are

    p* = 0.5461,

    q* = 0.5460, andr* = p* - q* = 0.0001.

    375.000016.0

    0001.000016.0*

    r

    rrerrorrelative

  • 7/27/2019 Lec 1 -2 Introduction

    17/43

    17

    Example 2

    The loss of accuracy due to round-off error can often beavoided by a reformulation of the problem, as illustrated

    in the next example.

    The quadratic formula states that the roots ofax2 + bx +

    c = 0, when a 0, are

    a

    acbbx

    a

    acbbx

    2

    4;

    2

    42

    2

    2

    1

    Using four-digit rounding arithmetic, consider this formulaapplied to the equation x2 + 62.10x + 1 = 0, whose roots

    are approximately

    x1 = -0.01610723 ; x2 = -62.08390

  • 7/27/2019 Lec 1 -2 Introduction

    18/43

    18

    Example 2

    06.62.3852000.4.3856

    )000.1)(000.1)(000.4()10.62(422

    acb

    0200.0

    2

    06.6210.62

    2

    4)1(

    2

    a

    acbbxfl

    In this equation, b2

    is much larger than 4ac, so thenumerator in the calculation for x involves the subtraction

    of nearly equal numbers. Since

    We then have

    Then relative error for x1= -0.01611 is

    1104.2

    01611.0

    02000.001611.0

    r

  • 7/27/2019 Lec 1 -2 Introduction

    19/43

    19

    Example 2

    10.62

    000.2

    2.124

    2

    06.6210.62

    2

    4)1(

    2

    a

    acbbxfl

    On the other hand, the calculation for x2 involves theaddition of the nearly equal numbers. This presents no

    problem since

    Then relative error for x1= -0.01611 is

    4

    102.308.62

    10.6208.62

    r

    This relative error is small.

  • 7/27/2019 Lec 1 -2 Introduction

    20/43

  • 7/27/2019 Lec 1 -2 Introduction

    21/43

    21

    Example 2

    acbbc

    x

    acbba

    ac

    acbb

    acbb

    a

    acbbx

    4

    2

    42

    4

    4

    4

    2

    4

    22

    22

    22

    2

    1109.108.62

    00.5008.62

    r

    If we use this formula for x2, it will be a mistake

    Using this we get

    This relative error is large due to

    subtraction of nearly equal

    numbers and a division.

    00.50

    0400.0

    000.2

    06.6210.62

    000.2)2(

    xfl

  • 7/27/2019 Lec 1 -2 Introduction

    22/43

    22

    Example 3Accuracy loss due to roundoff error can also be reduced by rearranging

    calculations, as shown in this example.

    Evaluate: f(x) = x3 6.1x2 + 3.2x + 1.5 at x = 4.71

    Use the three-digit arithmetic.

    Table gives the intermediate results in the calculations.

    Note that the three-digit chopping values simply retain the leading

    three digits, with no rounding involved, and differ significantly from the

    three-digit rounding values.

    x x2

    x3

    6.1x2

    3.2xExact 4.71 22.1841 104.487111 135.32301 15.072

    (chopping) 4.71 22.1 104. 134. 15.0

    (rounding) 4.71 22.2 105. 135. 15.1

  • 7/27/2019 Lec 1 -2 Introduction

    23/43

    23

    Example 3

    05.0263899.14

    5.13263899.14

    r

    Exact: f(4.71) = 104.487111 - 135.32301 + 15.072+ 1.5 = -14.263899;

    Three-digit (chopping): f(4.71) = ((104. - 134.) + 15.0) + 1.5 = -13.5;

    Three-digit (rounding): f(4.71) = ((105. - 135.) + 15.1) + 1.5 = -13.4.

    The relative errors for the three-digit:

    06.0263899.14

    4.13263899.14

    r

    For chopping:

    For rounding:

    As an alternative approach, f(x) can be written in a nested manner.

  • 7/27/2019 Lec 1 -2 Introduction

    24/43

    24

    Example 3

    As an alternative approach, f(x) can be written in a nested manner as

    f(x) = x3 - 6.1x2 + 3.2x + 1.5 = ((x - 6.1)x + 3.2)x + 1.5.

    This gives Three-digit (chopping):

    f(4.71) = ((4.71 - 6.1)4.71 + 3.2)4.71 + 1.5 = -14.2

    and a three-digit rounding answer of -14.3.

    The new relative errors are

    Three-digit (chopping): relative error = 0.0045;

    Three-digit (rounding): relative error = 0.0025

    Nesting has reduced the relative error for the chopping approximation

    to less than 10% of that obtained initially. For the rounding

    approximation the improvement has been even more dramatic; the

    error in this case has been reduced by more than 95%.

  • 7/27/2019 Lec 1 -2 Introduction

    25/43

  • 7/27/2019 Lec 1 -2 Introduction

    26/43

    26

    Software

    Operating Systems

    Windows - NT, ME, Windows

    Unix VMS - VAX

    Linux

  • 7/27/2019 Lec 1 -2 Introduction

    27/43

    27

    Software

    Languages

    Fundamental Assembler (Bit manipulations)

    Engineering Languages

    Fortran

    Cobol

    Pascal

    C++

    Basic

    HTML and Java

  • 7/27/2019 Lec 1 -2 Introduction

    28/43

    28

    Software

    Higher-Order Programming Maple - Mathematical Programming Language

    Mathematica - Mathematical ProgrammingLanguage

    Java - Internet Programming Language

    Matlab - Matrix Laboratory

  • 7/27/2019 Lec 1 -2 Introduction

    29/43

    29

    Software

    Tools Word Processors

    Spreadsheets

    Database Management Graphics

    Mathematical Computer Codes

  • 7/27/2019 Lec 1 -2 Introduction

    30/43

    30

    Matlab -Matrix Laboratory

    Currently Matlab 7.0 is available on This will be available on the network with a

    SIMULINK tool box

    Student Version is also available in the maket.

  • 7/27/2019 Lec 1 -2 Introduction

    31/43

    31

    What is a program?

    Program consist of three main components:

    Input

    Main Program - Numerical methods andanalysis and/or evaluation.

    Output - Results.

  • 7/27/2019 Lec 1 -2 Introduction

    32/43

    32

    Inputs

    Numerical values Initialization of the variables

    Conditions

    Equations

  • 7/27/2019 Lec 1 -2 Introduction

    33/43

    33

    Main Program

    Using flow charts, the programs can be designedto perform a task. Using:

    Loops

    Conditions

    Error Convergence

  • 7/27/2019 Lec 1 -2 Introduction

    34/43

    34

    Output

    Outputs are the results of the program. They can gothrough a series of post-processing methods.

    Numerical Values

    Decisions

    Graphs and Plots

  • 7/27/2019 Lec 1 -2 Introduction

    35/43

    35

    MatLab

    Variable Types Integers

    Real Values (Float)

    Complex Numbers (a + ib) a - real value

    b - imaginary value (i is the square root of-1)

  • 7/27/2019 Lec 1 -2 Introduction

    36/43

    36

    Matlab

    Data types Numerical

    Scalars

    Vectors

    Matrices

    Logic Types

    Alpha/Numerical Types

  • 7/27/2019 Lec 1 -2 Introduction

    37/43

    37

    Matlab

    A scalar value is the simple number, a, 2,3.14157,

    A vector is a union of ax = (x1, x2, x3, x4)

    Transpose vector xT = x1x2x3

    x4

  • 7/27/2019 Lec 1 -2 Introduction

    38/43

    38

    Matlab

    Matrix is a combination of vectors and scalars.Scalar and vectors are subsets of matrices.

    Matlab uses matrix to do mathematicalmethods.

  • 7/27/2019 Lec 1 -2 Introduction

    39/43

    39

    Matlab

    Set of computer functions Circular functions - sin(x),cos(x), tan(x), asin(x),

    acos(x), atan(x)

    Hyperbolic functions - sinh(x), cosh(x), tanh(x)

    Logarithmic functions - ln(x), log(x), exp(x)

    Logic functions - abs(x), real(x), imag(x)

  • 7/27/2019 Lec 1 -2 Introduction

    40/43

    40

    Matlab

    Simple commands clc - clears window

    clg - clear graphic window

    clear - clears the workspace who - variable list

    whos - variable list with size

    help - when doubt use it!

  • 7/27/2019 Lec 1 -2 Introduction

    41/43

    41

    Matlab

    Simple commands and symbols ^C - an escape from a loop

    inf - infinity

    NaN - No numerical value

  • 7/27/2019 Lec 1 -2 Introduction

    42/43

  • 7/27/2019 Lec 1 -2 Introduction

    43/43