MAT 4725 Numerical Analysis Section 1.4 Loops with “do” statements
Homework Download homework from the web Read while-do loop documentations format printing Quiz on 1.6.2, we will not lecture on that section
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
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
Monotonic Sequence Theorem The following sequences are convergent Increasing and bounded above Decreasing and bounded below
Example Show that the sequence defined by is convergent and find its limit.
Example From homework 01, we know
Zeng Section 1.4 Please listen to the explanations before you type in the program. It takes one minute to explain.
Example 1 Print the square of the first 10 positive integers What is the task being repeated?
Example 1
Example 1 > sq(); 1 4 9
Structure of the for loop
Example 2 Print the square of the first 10 positive odd integers
Example 2
> sq2();
Example 3 Print the square of the first n positive integers
Example 3 Print the square of the first n positive integers Introduces array and seq Note that these commands are not necessary here
Example 3
> sq3(2); 1, 4 > sq3(5); 1, 4, 9, 16, 25
Example 4 Fibonacci sequence is defined by
Example 4 Write a program that generate the first n+1 terms of the Fibonacci sequence F 0,F 1,…,F n
Example 4
What happen if we do not initialize F?
Example 4 Why there is no print statement?
Example 4
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.
Example 5