Presentation is loading. Please wait.

Presentation is loading. Please wait.

Numerical Analysis 1 EE, NCKU Tien-Hao Chang (Darby Chang)

Similar presentations


Presentation on theme: "Numerical Analysis 1 EE, NCKU Tien-Hao Chang (Darby Chang)"— Presentation transcript:

1 Numerical Analysis 1 EE, NCKU Tien-Hao Chang (Darby Chang)

2 Summary 2 2 exams, some exercises http://zoro.ee.ncku.edu.tw/na/

3 Target 3 Solve problems with numerical methods

4 In this slide Why numerical methods? –differences between human and computer –a very simple numerical method What is algorithm? –definition and components –three problems and three algorithms Convergence –compare rate of convergence 4

5 Why such methods? 5 Computer is stupid

6 x-2=0 6 Human says, “ x=2, easy!”

7 { x-2=0; } 7 Computer says, “compile error!”

8 What is the difference? 8

9 9 Human is logical (thinking) http://www.wallcoo.com/paint/Donald_Zolan_Early_Childhood_02/wallpapers/1280x1024/painting_children_kjb_DonaldZolan_68TheThinker_sm.jpg

10 10 Can do inference © http://files.myopera.com/conansakura/albums/31567/thumbs/2.jpg_thumb.jpg

11 11 Computer is procedural (executing) http://www.aclibrary.org/eventkeeper/Graphics/SLZ/computer.jpg

12 An example (((x+3)-2)+6)=0 –Human requires only the rules (in this case, arithmetic), –and can inference the steps for the solution 12

13 Computer (((x+3)-2)+6)=0 –Requires exact procedure (steps) { x0=0–6; } { x1=x0+2; } { x=x1–3; } –These steps is numerical method 13

14 14 Does computer have any advantage?

15 15 It is fast http://www.masternewmedia.org/images/fast_snail_id86636_size350.jpg

16 So, why numerical methods? Computer is stupid Computer is fast (and works hard) Sometimes, stupid methods can solve difficult problems 16

17 17

18 18

19 19 t d is the time of death, which cannot be solved explicitly

20 We know that 20 t d is no earlier than PM 7:15, and t d is no later than PM 8:00. So…

21 t d could be PM 7:38 21 rubbish =.=

22 A systematic procedure 1. Let t d as PM 7:38 2. Evaluate the above formula 3. If the result exceeds 98.6, we use PM 7:27, otherwise, we use PM 7:49 instead 4. Repeat step 2 & 3 until the result is close to 98.6 enough 22

23 Bisection method 23 http://www.leda-tutorial.org/en/unofficial/Pictures/BisectionMethod.png

24 Bisection method The concept is –1) find the mid-point, 2) evaluate it, and 3) shrink the solution range It is stupid: just trial and error But it works, because t d is ascending And… 24

25 And very accurate 25 Actually, it is getting accurate after every trial

26 When #trails → ∞ 26 Computer works hard, so it could happen

27 Any Questions? 27

28 Algorithm 28 The heart of numerical analysis

29 Algorithm Definition –A precisely defined sequence of steps In this course –design; –implement; and –examine the performance 29

30 30 How to implement?

31 By hand 31 too painful (but you might need to)

32 With computer 32 in other words, do programming

33 Programming 33 Even scared!

34 34 Algorithm could be simple

35 An example from statistics Mean and standard deviation on n values 35

36 36

37 In action 37 input is { 1, 2, 3, 4, 5 }

38 38

39 It is also an algorithm 39 (a precisely defined sequence of steps)

40 Not 40 A difficult sequence of steps

41 Any Questions? 41

42 Another example 42 Definite integral using trapezoidal rule

43 43 A partition a = x 0 < x 1 < x 2 < … < x n-1 < x n = b

44 44 where x i = a + i h, and h = ( b – a ) / n

45 45

46 In action 46 f(x) = 1 / x, n = 4

47 47

48 Error The analytic solution is ln2 The absolute error is 48

49 49

50 Observations of the errors |e n |, the absolute error, is a decreasing function of n When n is doubled, |e n | is reduced by a factor (roughly 1/4) From the numerical evidence where c is independent of n 50

51 Any Questions? 51

52 The third example Square root – a is a nonnegative real number – x n+1 converges to sqrt(a) 52

53 53

54 Stopping condition |x n+1 – sqrt(a)| <ε – |x n+1 – x n | <ε provides an estimate Prevent infinite loop –give a limit of the number of iterations 54

55 In action 55 sqrt(2), i.e., a=2 x 0 = 2, ε = 0.005, Nmax = 10

56 56

57 So far 57 a statistics problem, the integral problem, and the square root problem

58 Any Questions? 58

59 59 What is the differences among them? (hint: the concepts of the output)

60 Type of methods The statistics algorithm –generates an exact (analytic) solution The integral algorithm –generates an approximate (numerical) solution –many numerical methods work in much the same way The square root algorithm –generates a sequence of approximations which converge to the solution –another typical class of numerical methods 60

61 Poll 61 Programming ability

62 Learnt 62 C/C++ (??/23) Java (??/23) Other (??/23)

63 Learnt 63 Data structure (??/23) Algorithm (??/23)

64 Language vs. algorithm Two languages –The same concept, different patterns –e.g., Chinese and English – 想睡覺, feel sleepy English vs. C –Increase i by 1 –{ ++i; } Language is/defines the pattern Algorithm is/describes the concept 64

65 Pseudo-code 65 Not any real programming language

66 A pseudo-code example 66

67 Can You 67 Read/write pseudo-code?

68 Convergence 68 When several numerical methods are available, choose the fastest one

69 69 The sequence {x n } converges to the value L, and L is called the limit of the sequence

70 Rate of convergence Let {p n } converges to p, {β n } converges to 0, λ is a constant, and Rate of convergence of {p n } is O(β n ) O(β n ) is typically of the form – 1/n a – 1/a n 70

71 71

72 72

73 73

74 74

75 Any Questions? 75

76 Which Is Better? 76 O(1/n 2 ), O(1/n 10 ), or O(1/2 n )

77 Using L'Hôpital's rule This is provided by a student 陳攀任 In its simplest form, l'Hôpital's rule states that for functions ƒ and g : To compare n 10 and 2 n 77

78 78

79 Rate of Convergence 79 There is another definition for function

80 Another definition of rate of convergence for function 80

81 81

82 Rate of convergence Let {p n } converges to p, {β n } converges to 0, λ is a constant, and Rate of convergence of {p n } is O(β n ) O(β n ) is typically of the form – 1/n a – 1/a n 82

83 Order of Convergence A different measure of convergence speed than rate of convergence Examines the relationship between successive error values 83

84 Order of Convergence Iterative Method An iterative method is said to be of order α if the sequence it generates converges of order α The most common values of α in practice are –α = 1 (linear convergence) –α = 2 (quadratic convergence) –α = 3 (cubic convergence) Non-integer values for α are possible 84

85 85 Note the dramatic difference between 1 and 2, and the slight difference between 2 and 3

86 86


Download ppt "Numerical Analysis 1 EE, NCKU Tien-Hao Chang (Darby Chang)"

Similar presentations


Ads by Google