Download presentation
Presentation is loading. Please wait.
1
Introduction to Scientific Computing ICE 26.466 / ICE 508 Prof. Hyuckjae Lee KAIST- ICC hjlee@icu.ac.kr
2
2 How did little Pascal do ? Add from 1 to 100 ? –Pascal did it as follows, 1, 2, 3, 4, ……………….., 99, 100 + 100, 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 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
4 Simple Polynomial Computation Computation of in Java or C No. of Multiplications
5
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
6 Polynomial Computation Ex) 1)Wild count of * : 5 + 4 + 3 + 2 +1 15 2)From previous count of each powers : 4 + 3 + 3 + 2 + 1 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
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
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
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
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 =.000001 ; 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
11 Note avoids N ! computation avoid repeated computations ! Each term : : Starting condition needed Many functions have similar expansion properties.
12
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
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
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 10 -7. Why ?
15
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
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
17 Algorithm (Rule) finding : for c = 2, will be studied in later session
18
18 Errors in Scientific Computation Rounding Errors Truncation Errors Data (Measurement) Errors Modeling (Simplification) Errors Human Errors
19
19 Errors Absolute error : Loss of significance Relative error : Error propagation – Addition and subtraction : – Multiplication and division : Stability/Conditioning
20
20 Loss of significant digits – When subtracting nearly equal values Typical example: Quadratic roots : Demo. will be shown later.
21
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
22 Stable/Unstable Algorithm Show by example Compute for Recursive formula as In computation, just use three decimals,
23
23 Algorithm I Why is it unstable?
24
24 Algorithm II Make use of recursive formula in reverse order as Why is this correct and stable?
25
25 Orders of Convergence Big O small o
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.