Yasser F. O. Mohammad 2010.9.22. Approximations and Round-off Errors.

Slides:



Advertisements
Similar presentations
MATLAB – A Computational Methods By Rohit Khokher Department of Computer Science, Sharda University, Greater Noida, India MATLAB – A Computational Methods.
Advertisements

Introduction to Matlab
Introduction to Matlab Workshop Matthew Johnson, Economics October 17, /13/20151.
Roundoff and truncation errors
2009 Spring Errors & Source of Errors SpringBIL108E Errors in Computing Several causes for malfunction in computer systems. –Hardware fails –Critical.
ECIV 201 Computational Methods for Civil Engineers Richard P. Ray, Ph.D., P.E. Error Analysis.
Approximations and Errors
Round-Off and Truncation Errors
Introduction to Matlab By: Dr. Maher O. EL-Ghossain.
The Islamic University of Gaza Faculty of Engineering Civil Engineering Department Numerical Analysis ECIV 3306 Chapter 3 Approximations and Errors.
Getting started with Matlab Numerical Methods Appendix B help/techdoc/learn_matlab/learn_matlab.html.
Introduction to Matlab Οικονομίδης Δημήτρης
1 Error Analysis Part 1 The Basics. 2 Key Concepts Analytical vs. numerical Methods Representation of floating-point numbers Concept of significant digits.
Introduction to MATLAB MECH 300H Spring Starting of MATLAB.
CISE-301: Numerical Methods Topic 1: Introduction to Numerical Methods and Taylor Series Lectures 1-4: KFUPM.
259 Lecture 15 Introduction to MATLAB. 2 What is MATLAB?  MATLAB, which stands for “MATrix LABoratory” is a high- performance language for technical.
1 Statistical Computing in MATLAB AMS 597 Ling Leng.
Martin Ellison University of Warwick and CEPR Bank of England, December 2005 Introduction to MATLAB.
Engineering Analysis ENG 3420 Fall 2009 Dan C. Marinescu Office: HEC 439 B Office hours: Tu-Th 11:00-12:00.
Nonparametric Econometrics1 Intro to Matlab for Data Analysis and Statistical Modeling.
Introduction to Matlab 1. Outline: What is Matlab? Matlab Screen Variables, array, matrix, indexing Operators Plotting Flow Control Using of M-File Writing.
Eng Advanced Marine Vehicles Todays agenda: Lab tomorrow at 2pm (structures lab) ‏ Advanced Marine Party Introduction to Matlab.
Lecture 2 Number Representation and accuracy
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:
ELG 3120 Signal and System Analysis 1 Introduction to MATLAB TAs Wei Zhang Ozgur Ekici (Section A)(Section B) ELG 3120 Lab Tutorial 1.
ECE 1304 Introduction to Electrical and Computer Engineering Section 1.1 Introduction to MATLAB.
A Brief Introduction to Matlab Laila Guessous Dept. of Mechanical Engineering Oakland University.
Eng Ship Structures 1 Introduction to Matlab.
INTRODUCTION TO MATLAB LAB# 01
1 Computer Programming (ECGD2102 ) Using MATLAB Instructor: Eng. Eman Al.Swaity Lecture (1): Introduction.
Numerical Computation Lecture 2: Introduction to Matlab Programming United International College.
Matlab Basics Tutorial. Vectors Let's start off by creating something simple, like a vector. Enter each element of the vector (separated by a space) between.
What is MATLAB? MATLAB is one of a number of commercially available, sophisticated mathematical computation tools. Others include Maple Mathematica MathCad.
MECN 3500 Inter - Bayamon Lecture 3 Numerical Methods for Engineering MECN 3500 Professor: Dr. Omar E. Meza Castillo
Matlab The language of Technical computing Mr. D. Suresh Assistant Professor, Dept. of CSE, PSNA CET, Dindigul.
Matlab 14.html Cost: $100 Available in labs on Windows and Unix machines.
OUTLINE Overview Numbers, variables and similar in Matlab
Introduction to Matlab. Outline:  What is Matlab? Matlab Screen Variables, array, matrix, indexing Operators (Arithmetic, relational, logical ) Display.
Introduction to Matlab. What is Matlab? A software environment for interactive numerical computations Examples:  Matrix computations and linear algebra.
Matlab Screen  Command Window  type commands  Current Directory  View folders and m-files  Workspace  View program variables  Double click on a.
Computer Simulation Lab Electrical and Computer Engineering Department SUNY – New Paltz SUNY-New Paltz “Lecture 2”
Meeting 15 Introduction to Numerical Methods Error Analysis.
Lecture 20: Choosing the Right Tool for the Job. What is MATLAB? MATLAB is one of a number of commercially available, sophisticated mathematical computation.
A simple classification problem Extract attributes Pattern Pattern recognition decision x C1 C2.
1 Introduction to Matlab-2 Laboratoire Mathématiques, Informatique et Applications.
Numerical Analysis CC413 Propagation of Errors.
Introduction to Matlab  Matlab is a software package for technical computation.  Matlab allows you to solve many numerical problems including - arrays.
Introduction to Matlab
INTRODUCTION TO MATLAB Dr. Hugh Blanton ENTC 4347.
Introduction to MATLAB 1.Basic functions 2.Vectors, matrices, and arithmetic 3.Flow Constructs (Loops, If, etc) 4.Create M-files 5.Plotting.
Errors in Numerical Methods
Introduction to Matlab Engr. Mian Shahzad Iqbal LAB NO.2
CS100A, Fall 1998, Lecture 201 CS100A, Fall 1998 Lecture 20, Tuesday Nov 10 More Matlab Concepts: plotting (cont.) 2-D arrays Control structures: while,
Matlab Tutorial (material available at 1 Dr. Jim Martin Associate Professor School of Computing.
MATLAB (Matrix Algebra laboratory), distributed by The MathWorks, is a technical computing environment for high performance numeric computation and.
Numerical Analysis CC413 Propagation of Errors. 2 In numerical methods, the calculations are not made with exact numbers. How do these inaccuracies propagate.
Introduction to Matlab. Outline:  What is Matlab? Matlab Screen Variables, array, matrix, indexing Operators.
Introduction to MATLAB
Statistical Computing in MATLAB
Taylor series in numerical computations (review)
INTRODUCTION TO BASIC MATLAB
MATLAB DENC 2533 ECADD LAB 9.
Introduction to Matlab
Matlab Workshop 9/22/2018.
StatLab Matlab Workshop
Use of Mathematics using Technology (Maltlab)
StatLab Workshop: Intro to Matlab for Data Analysis and Statistical Modeling 11/29/2018.
Approximations and Round-Off Errors Chapter 3
CISE-301: Numerical Methods Topic 1: Introduction to Numerical Methods and Taylor Series Lectures 1-4: KFUPM CISE301_Topic1.
Presentation transcript:

Yasser F. O. Mohammad

Approximations and Round-off Errors

Numerical methods yield approximate results. The significant digits or figures of a number are those that can be used with confidence.  They correspond to the number of certain digits plus one estimated digit. Significant Figures

One might say the speed is between 48 and 49 km/h. Thus, we have a 2-significant figure reading. I can say the speed is between 48.5 and 48.9 km/h. Thus, we have a 3-significant figure reading.

We say the number 4.63±0.01 has 3 significant figures.

Rules regarding the zero: Zeros within a number are always significant: 5001 and have 4 significant figures Zeros to the left of the first nonzero digit in a number are not significant: , , have 4 significant figures Trailing zeros are significant: 6.00 has 3 sig. figures may have 3, 4, or 5 sig. figures, we can know if the number is written in the scientific notation: 4.53×10 4 has 3 sig. figures 4.530×10 4 has 4 sig. figures ×10 4 has 5 sig. figures

Error Definitions Truncation errors result when approximations are used to represent exact mathematical procedures. Round-off errors result when numbers having limited significant figures are used to represent exact numbers. Example: We know that Lets approximate the value of by (using only 5 decimal places). Then,Round-off error

The relationship between the exact (true) result and the approximation is given by true value = approximation + error Hence, the error is the difference between the true value and the approximation: true error = E t = true value - approximation Most of the time we will use what we call the true fractional relative error

Or we use the true percent relative error  t = Example your measurement of the length of the bridge is 999. the true length is E t = = 1  t = = 0.01 %

In real world applications, the true value is not known. Approximate error =  a =  a = The computation is repeated until |  a | <  s We usually use  s = (0.5×10 2-n )% if we want the result to be correct to at least n significant figures.

Round-off Errors Round-off errors occur because computers retain only a fixed number of significant figures. We use the decimal (base 10) system which uses the 10 digits 0, 1, …, 9.

Numbers on the computers are represented with a binary (base 2) system.

How are numbers represented in computers? Numbers are stored in what is called ‘word’. A word has a number of bits, each bit holds either 0 or 1. For example, -173 is presented on a 16-bit computer as Word

On a 16-bit computer, the range of numbers that can be represented is between -32,768 and 32,767.

Floating Point Representation Word (normal form) ×10 3 (floating point form)

There is a limited range of numbers that can be represented on computers. Conclusion

Rounding Rounding up is to increase by one the digit before the part that will be discarded if the first digit of the discarded part is greater than 5. If it is less than 5, the digit is rounded down. If it is exactly 5, the digit is rounded up or down to reach the nearest even digit. Round 1.14 to one decimal place: 1.1 Round 1.15 to one decimal place: 2.2 Round to one decimal place: 21.8

Chopping Chopping is done by discarding a part of the number without rounding up or down. Chop 1.15 to one decimal place: 1.1 Chop 0.34 to one decimal place: 0.3 Chop to one decimal place: 21.7

Truncation Errors and the Taylor Series

The Taylor Series Taylor’s Theorem If the function f and its first n +1 derivatives are continuous on an interval containing a and x, then the value of the function at x is given by: where the remainder R n is defined as

Using Taylor’s Theorem, we can approximate any smooth function by a polynomial. The zero-order approximation of the value of f(x i+1 ) is given f(x i+1 )  f(x i ) The first-order approximation is given by f(x i+1 )  f(x i ) + f '(x i )(x i+1 -x i )

The complete Taylor series is given by The remainder term is where  is between x i and x i+1

Notes We usually replace the difference (x i+1 - x i ) by h. A special case of Taylor series when x i = 0 is called Maclaurin series.

Example Use Taylor series expansions with n = 0 to 6 to approximate f(x) = cos x near x i =  /4 at x i+1 =  /3. Solution h =  /3 -  /4 =  /12 Zero-order approximation: f(  /3)  cos (  /4) =  t = First-order approximation: f(  /3)  cos (  /4) – (  /12) sin (  /4) =  t = -4.4%

To get more accurate estimation of f(x i+1 ), we can do one or both of the following:  add more terms to the Taylor polynomial  reduce the value of h.

Taylor series in MATLAB >> syms x; >> f=cos(x); >> taylor(f,3,pi/4) Required! Taylor function in MATLAB Number of terms in the series Expansion point

Matlab Basics MATrix LABoratory Based on LAPACK library (NOW CLAPACK exists for C programmers) A high level language and IDE for numerical methods and nearly everything else!! Easy to use and learn The most important command in Matlab help ANYTHING Lookfor ANYTHING

Matlab Screen Command Window type commands Workspace view program variables clear to clear double click on a variable to see it in the Array Editor Command History view past commands save a whole session using diary Launch Pad access tools, demos and documentation

Matlab Files Use predefined functions or write your own functions Reside on the current directory or the search path add with File/Set Path Use the Editor/Debugger to edit, run

Matrices a vector x = [ ] x = a matrix x = [1 2 3; 5 1 4; ] x = transpose y = x.’ y =

Matrices x(i,j) subscription whole row whole column y=x(2,3) y = 4 y=x(3,:) y = y=x(:,2) y = 2 1 2

Operators (arithmetic) +addition -subtraction *multiplication /division ^power ‘complex conjugate transpose.*element-by-element mult./element-by-element div.^element-by-element power.‘transpose

Operators (relational, logical) ==equal ~=not equal <less than <=less than or equal >greater than >=greater than or equal &AND |OR ~NOT pi … jimaginary unit, isame as j

Generating Vectors from functions zeros(M,N)MxN matrix of zeros ones(M,N)MxN matrix of ones rand(M,N)MxN matrix of uniformly distributed random numbers on (0,1) x = zeros(1,3) x = x = ones(1,3) x = x = rand(1,3) x =

Operators [ ]concatenation ( )subscription x = [ zeros(1,3) ones(1,2) ] x = x = [ ] x = y = x(2) y = 3 y = x(2:4) y = 3 5 7

Matlab Graphics x = 0:pi/100:2*pi; y = sin(x); plot(x,y) xlabel('x = 0:2\pi') ylabel('Sine of x') title('Plot of the Sine Function')

Multiple Graphs t = 0:pi/100:2*pi; y1=sin(t); y2=sin(t+pi/2); plot(t,y1,t,y2) grid on

Multiple Plots t = 0:pi/100:2*pi; y1=sin(t); y2=sin(t+pi/2); subplot(2,2,1) plot(t,y1) subplot(2,2,2) plot(t,y2)

Graph Functions (summary) plotlinear plot stemdiscrete plot gridadd grid lines xlabeladd X-axis label ylabel add Y-axis label titleadd graph title subplotdivide figure window figurecreate new figure window pausewait for user response

Math Functions Elementary functions (sin, cos, sqrt, abs, exp, log10, round) type help elfun Advanced functions (bessel, beta, gamma, erf) type help specfun type help elmat

Functions function f=myfunction(x,y) f=x+y; save it in myfunction.m call it with y=myfunction(x,y)

Flow Control if A > B 'greater' elseif A < B 'less' else 'equal' end for x = 1:10 r(x) = x; end if statement switch statement for loops while loops continue statement break statement

Miscellaneous Loading data from a file load myfile.dat Suppressing Output x = [ ];

Getting Help Using the Help Browser (.html,.pdf) View getstart.pdf, graphg.pdf, using_ml.pdf Type help help function, e.g. help plot Running demos type demos type help demos

Random Numbers x=rand(100,1); stem(x); hist(x,100)