Introduction to Scientific Computing ICE 26.466 / ICE 508 Prof. Hyuckjae Lee KAIST- ICC

Slides:



Advertisements
Similar presentations
3- 1 Chapter 3 Introduction to Numerical Methods Second-order polynomial equation: analytical solution (closed-form solution): For many types of problems,
Advertisements

Python Crash Course Accuracy 3 rd year Bachelors V1.0 dd Hour 7.
Roundoff and truncation errors
2009 Spring Errors & Source of Errors SpringBIL108E Errors in Computing Several causes for malfunction in computer systems. –Hardware fails –Critical.
Overview CNS 3320 – Numerical Software Engineering.
Types and Arithmetic Operators
Numerical Analysis 1 EE, NCKU Tien-Hao Chang (Darby Chang)
Primitive Data Types There are a number of common objects we encounter and are treated specially by almost any programming language These are called basic.
Asymptotic error expansion Example 1: Numerical differentiation –Truncation error via Taylor expansion.
ECIV 201 Computational Methods for Civil Engineers Richard P. Ray, Ph.D., P.E. Error Analysis.
10-Jun-15 Introduction to Primitives. 2 Overview Today we will discuss: The eight primitive types, especially int and double Declaring the types of variables.
©2004 Brooks/Cole Chapter 2 Variables, Values and Operations.
1 Fundamental Data types Overview l Primitive Data Types l Variable declaration l Arithmetical Operations l Expressions l Assignment statement l Increment.
Introduction to Primitives. Overview Today we will discuss: –The eight primitive types, especially int and double –Declaring the types of variables –Operations.
The Islamic University of Gaza Faculty of Engineering Civil Engineering Department Numerical Analysis ECIV 3306 Chapter 3 Approximations and Errors.
CS180 Recitation 3. Lecture: Overflow byte b; b = 127; b += 1; System.out.println("b is" + b); b is -128 byte b; b = 128; //will not compile! b went out.
CSE 378 Floating-point1 How to represent real numbers In decimal scientific notation –sign –fraction –base (i.e., 10) to some power Most of the time, usual.
1 Error Analysis Part 1 The Basics. 2 Key Concepts Analytical vs. numerical Methods Representation of floating-point numbers Concept of significant digits.
Computer Arithmetic Integers: signed / unsigned (can overflow) Fixed point (can overflow) Floating point (can overflow, underflow) (Boolean / Character)
Scientific Computing Algorithm Convergence and Root Finding Methods.
Introduction and Analysis of Error Pertemuan 1
Floating Point Computation
Simple Data Type Representation and conversion of numbers
Chapter 1 Algorithm Analysis
 2003 Prentice Hall, Inc. All rights reserved. 1 Introduction to C++ Programming Outline Introduction to C++ Programming A Simple Program: Printing a.
Numerical Computations in Linear Algebra. Mathematically posed problems that are to be solved, or whose solution is to be confirmed on a digital computer.
Fall, 2006Introduction to FORTRAN1 (2 + 2 = ???) Numbers, Arithmetic Nathan Friedman Fall, 2006.
Lecture 2 Number Representation and accuracy
MATH 685/CSI 700 Lecture Notes Lecture 1. Intro to Scientific Computing.
CISE301_Topic11 CISE-301: Numerical Methods Topic 1: Introduction to Numerical Methods and Taylor Series Lectures 1-4:
DEPARTMENT OF COMPUTER SCIENCE & TECHNOLOGY FACULTY OF SCIENCE & TECHNOLOGY UNIVERSITY OF UWA WELLASSA 1 CST 221 OBJECT ORIENTED PROGRAMMING(OOP) ( 2 CREDITS.
College of Engineering Representing Numbers in a Computer Section B, Spring 2003 COE1361: Computing for Engineers COE1361: Computing for Engineers 1 COE1361:
Data Representation in Computer Systems
Analysis of Algorithms
Representing numbers and Basic MATLAB 1. Representing numbers  numbers used by computers do not behave the same as numbers used in mathematics  e.g.,
Round-off Errors.
Floating Point Arithmetic
Numbers. Kinds of numbers There are basically two kinds of numbers Integers: …, -3, -2, -1, 0, 1, 2, 3, … “Real” numbers: 2.5, 0.002, 3.14…, 1.6x10 20.
CSE1222: Lecture 2The Ohio State University1. mathExample2.cpp // math example #include using namespace std; int main() { cout
Programming for Beginners Martin Nelson Elizabeth FitzGerald Lecture 2: Variables & Data Types.
Numerical Methods.
Numerical Analysis Intro to Scientific Computing.
Lecture 4 - Numerical Errors CVEN 302 June 10, 2002.
Numerical Analysis CC413 Propagation of Errors.
Numerical Analysis. Numerical Analysis or Scientific Computing Concerned with design and analysis of algorithms for solving mathematical problems that.
Ch13-1 Chap 13 Introduction to Matlab 13.1 Introduction MATLAB : The MATrix LABoratory program Not only is the MATLAB programming language exceptionally.
School of Computer Science & Information Technology G6DICP - Lecture 4 Variables, data types & decision making.
1 Programming a Computer Lecture Ten. 2 Outline  A quick introduction to the programming language C  Introduction to software packages: Matlab for numerical.
Spring 2006CISC101 - Prof. McLeod1 Announcements Assn 4 is posted. Note that due date is the 12 th (Monday) at 7pm. (Last assignment!) Final Exam on June.
Primitive Data Types. int This is the type you are familiar with and have been using Stores an integer value (whole number) between -2,147,483,648 (-2.
INTRO2CS Tirgul 8 1. Searching and Sorting  Tips for debugging  Binary search  Sorting algorithms:  Bogo sort  Bubble sort  Quick sort and maybe.
Numerical Analysis CC413 Propagation of Errors. 2 In numerical methods, the calculations are not made with exact numbers. How do these inaccuracies propagate.
Module 2.2 Errors 03/08/2011. Sources of errors Data errors Modeling Implementation errors Absolute and relative errors Round off errors Overflow and.
Lecture 3: More Java Basics Michael Hsu CSULA. Recall From Lecture Two  Write a basic program in Java  The process of writing, compiling, and running.
Cosc 2150: Computer Organization Chapter 9, Part 3 Floating point numbers.
NUMERICAL ANALYSIS I. Introduction Numerical analysis is concerned with the process by which mathematical problems are solved by the operations.
Chapter 7: Expressions and Assignment Statements
UNIVERSITY OF MASSACHUSETTS Dept
Analysis of Algorithms
Chapter 7: Expressions and Assignment Statements
Type Conversion, Constants, and the String Object
Data Structures Mohammed Thajeel To the second year students
Errors in Numerical Methods
Errors in Numerical Methods
How to represent real numbers
Introduction to Primitives
Introduction to Primitives
Unit 3: Variables in Java
Chapter 1 / Error in Numerical Method
Presentation transcript:

Introduction to Scientific Computing ICE / ICE 508 Prof. Hyuckjae Lee KAIST- ICC

2 How did little Pascal do ?  Add from 1 to 100 ? –Pascal did it as follows, 1, 2, 3, 4, ……………….., 99, , 99, 98, 97,………………..., 2, 1 101, 101,101,101,……………….,101, 101 Therefore, 101* 100 / 2  5,050 –In general, he found the rule as  Lessons – Efficiency for Computing ; Reduction of Number of Operation – General Rule Finding ( iterative or recursive)

3 3 Good Programming Basics 1.General Rule Finding –Iterative Relation –Recursive Relation 2.Starting Condition and Stopping Criteria 3.Avoidance of Repeated Computation 4. Avoidance for Loss of Significant Digits

4 Simple Polynomial Computation  Computation of in Java or C No. of Multiplications

5 Wait a moment, those are not good as will be shown here  This kind of skills to reduce the required number of operations may apply many scientific problems as well as many engineering problems.

6  Polynomial Computation Ex) 1)Wild count of * :  15 2)From previous count of each powers :  13 3)Better Method : : needs 5 multiplications and 5 additions (common for every methods)  For n th degree polynomials, it only needs n mults and n adds !! ( Horner’s rule)

7 Note  In the past, multiplication cost a lot more than addition in computer.  “x+x” preferred over “2.0*x”  Modern computers by utilizing parallel and pipeline processing, multiplication cost almost same as addition. In many processors, mult. and addition is done in one command.

8  For General n th degree polynomials: 1.Wild method : n(n+1)/2 multi. and n adds 2.Horner’s method : n multi. and n adds sum = a[0] ; for ( i=1; i<= n; i++) sum = a[i]+x*sum ;

9  Another less efficient than Horner’s, but very useful sum = a[0]; xpower = 1 for (i = 1; i <= n; i++) { xpower = xpower* x ; sum = sum + xpower * a[i] ; }  2n mults and n adds  This form is more useful when computing function values by (in)finite series expansion, for many cases we do not know when to stop.

10 Computation of function by infinite series expansion  Exponential Function /* compute exp( x), and x is given */ int i, N ; float sum, term, eps ; eps = ; N = 100 ; sum = 1. ; term = 1. ; for ( i = 1; i <= N ; i++ ) { term = - term* x / i ; sum = sum + term ; if ( abs ( term / sum) < eps) return sum ;} /* else erroneous value return */ –Later, it will be shown that this series expansion has some serious defects of losing accuracy during computation for large argument. stopping criteria starting condition

11 Note  avoids N ! computation  avoid repeated computations ! Each term : : Starting condition needed  Many functions have similar expansion properties.

12 Number System in Computer  Arithmetic Number System –Natural numbers: 1, 2, 3, 4,….. Good for addition –Integer numbers: … -2, -1, 0, 1, 2, 3, …. Good for subtraction Good for multiplication –Real numbers : Good for division –Complex numbers: a + b i or a + b j Good for finding roots of polynomials

13  Basic Variables in computer languages –Numbers: Integer: int, byte, short, long Real : float, double Complex : not used in Java and C++, but used in Scientific Computation Language like old FORTRAN and MatLab –Characters: char –Boolean : boolean  Floating-Point representation –IEEE standards for single precision (32 bits) and double precision (64bits)  will be followed later

14  Tips in handling real variables for comparison –For integer variables a and b computed: good if ( a == b) –For real variables when a and b are computed thru : never do if (a == b), instead use if ( abs(a-b) < eps), where eps is very small bound like Why ?

15 Procedure for Scientific Computation  Modeling  Choice of mathematical methods, and numerical algorithm –Conditioning / Sensitivity Issue –Stability Issue  Programming : MatLab, Fortran, C or Java, ……  Computation  Approximate solutions  Interpretation of results

16 Algorithm  Sequence of rules for performing computation – Must have “stopping criteria” – Stable or unstable algorithm – Well-conditioned or ill-conditioned  Numerical instability may be avoided by choosing better algorithm, but mathematical instability is difficult to tackle.

17  Algorithm (Rule) finding : for c = 2, will be studied in later session

18 Errors in Scientific Computation  Rounding Errors  Truncation Errors  Data (Measurement) Errors  Modeling (Simplification) Errors  Human Errors

19 Errors  Absolute error : Loss of significance  Relative error :  Error propagation – Addition and subtraction : – Multiplication and division :  Stability/Conditioning

20 Loss of significant digits – When subtracting nearly equal values Typical example: Quadratic roots : Demo. will be shown later.

21 Well / ill Conditioning  Show by simple geometric example a)well-conditioned: small change of input  small change of solution b) ill-conditioned: small change of input, -> large change of solution c) no solution

22 Stable/Unstable Algorithm  Show by example Compute for  Recursive formula as In computation, just use three decimals,

23  Algorithm I  Why is it unstable?

24  Algorithm II Make use of recursive formula in reverse order as  Why is this correct and stable?

25 Orders of Convergence  Big O  small o