Presentation is loading. Please wait.

Presentation is loading. Please wait.

MAT 4725 Numerical Analysis Section 1.4 Loops with “do” statements

Similar presentations


Presentation on theme: "MAT 4725 Numerical Analysis Section 1.4 Loops with “do” statements"— Presentation transcript:

1 MAT 4725 Numerical Analysis Section 1.4 Loops with “do” statements http://myhome.spu.edu/lauw

2 Homework Download homework from the web Read 2.1.4 while-do loop 1.6.1 documentations 1.6.2 format printing Quiz on 1.6.2, we will not lecture on that section

3 Preview Monotonic Sequence Theorem (Stewart, section 12.1) Introduce the first type of repetition statements – the for loop Allow a specific section of code to be executed a number of times Introduces simple arrays

4 Definition A sequence {a n } is bounded above if  M such that a n  M  n A sequence {a n } is bounded below if  m such that a n  m  n

5 Monotonic Sequence Theorem The following sequences are convergent Increasing and bounded above Decreasing and bounded below

6 Example Show that the sequence defined by is convergent and find its limit.

7 Example From homework 01, we know

8

9 Zeng Section 1.4 Please listen to the explanations before you type in the program. It takes one minute to explain.

10 Example 1 Print the square of the first 10 positive integers What is the task being repeated?

11 Example 1

12 1210 14100

13 Example 1 > sq(); 1 4 9

14 Structure of the for loop

15

16 Example 2 Print the square of the first 10 positive odd integers

17 Example 2

18 > sq2(); 1 9 25

19 Example 3 Print the square of the first n positive integers

20 Example 3 Print the square of the first n positive integers Introduces array and seq Note that these commands are not necessary here

21 Example 3

22

23 > sq3(2); 1, 4 > sq3(5); 1, 4, 9, 16, 25

24 Example 4 Fibonacci sequence is defined by

25 Example 4 Write a program that generate the first n+1 terms of the Fibonacci sequence F 0,F 1,…,F n

26 Example 4

27 What happen if we do not initialize F?

28 Example 4 Why there is no print statement?

29 Example 4

30 Example 5 Write a program, for the input of x and n, to approximate the value of sin(x) by the first sum of the first n+1 terms in the Taylor series.

31 Example 5

32

33


Download ppt "MAT 4725 Numerical Analysis Section 1.4 Loops with “do” statements"

Similar presentations


Ads by Google