bilqis1 Pertemuan
bilqis2 Sequences and Summations Deret (urutan) dan Penjumlahan
bilqis3 Deret: Adalah sebuah fungsi dari himpunan bagian integer ke suatu himpunan S. Himpunan bagian integer yang dimaksud adalah {0, 1, 2, …} atau {1, 2, 3, …} S = { a 0, a 1, a 2, a 3, …, a n } atau { a 1, a 2, a 3, …, a n } Geometric progression: a, ar, ar 2, ar 3, …, ar n r = ratio Arithmetic progression: a, a+d, a+2d, …, a+nd d = different String: a 1 a 2 a 3 … a n empty string =
bilqis4 Sequence Sequence = urutan Sequence : –Struktur diskrit yg digunakan untuk merepresentasikan urutan elemen –Fungsi dari N ke S –A n image dari integer n Example: subset of N: … S: … f N dimulai dari 1
bilqis5 Sequences We use the notation {a n } to describe a sequence. Important: Do not confuse this with the {} used in set notation. It is convenient to describe a sequence with a formula. For example, the sequence on the previous slide can be specified as {a n }, where a n = 2n.
bilqis6 The Formula Game 1, 3, 5, 7, 9, … a n = 2n , 1, -1, 1, -1, … a n = (-1) n 2, 5, 10, 17, 26, … a n = n , 0.5, 0.75, 1, 1.25 … a n = 0.25n 3, 9, 27, 81, 243, … a n = 3 n What are the formulas that describe the following sequences a 1, a 2, a 3, … ?
bilqis7 Strings Finite sequences are also called strings, denoted by a 1 a 2 a 3 …a n. String kumpulan sequence –Ex : The length of a string S is the number of terms that it consists of. Length jumlah elemen pada string The empty string contains no terms at all. It has length zero. Empty string string yang tidak ada element –Length = 0
bilqis8 Contoh The sequence {bn} dgn bn=(-1) n adalah geometric progression. Kita mulai pada n=0, maka b0, b1, b2, b3 ….adalah 1, -1, 1, -1, ……… The sequence {Sn} dgn Sn = n adalah aritmatic progression. Kita mulai pada n=0, maka S0, S1, S2, S3 ….adalah -1, 3, 7, 11, ……
bilqis9
10
bilqis11
bilqis12
bilqis13 Penjumlahan (summation): a j = a m + a m+1 + a m+2 + … + a n m disebut batas bawah n disebut batas atas j disebut indeks n j = m
bilqis14 Summations It is = 21. We write it as. What is the value of ? It is so much work to calculate this… What is the value of ? How can we express the sum of the first 1000 terms of the sequence {a n } with a n =n 2 for n = 1, 2, 3, … ?
bilqis15 Summations It is said that Friedrich Gauss came up with the following formula: When you have such a formula, the result of any summation can be calculated much more easily, for example:
bilqis16 Double Summations Corresponding to nested loops in C or Java, there is also double (or triple etc.) summation: Example:
bilqis17 Double Summations Table 2 in Section 3.2 (4 th edition: Section 1.7) contains some very useful formulas for calculating sums. Exercises 15 and 17 make a nice homework.
bilqis18
bilqis19
bilqis20
bilqis21
bilqis22
bilqis23
bilqis24 Definisi Rekursif
bilqis25 Rekursif Rekursif –perulangan terhadap diri sendiri, dengan ukuran lebih kecil –Ada titik berhenti, apakah pada 0 atau pada 1 –Secara prinsip mirip dengan induksi : Ada nilai awal Ada rumus untuk selanjutnya Ex : 1 hal 203 – misal f didefinisikan sbb : F(0) = 3 F(n+1) = 2 f(n) + 3 Tentukan f(1), f(2), f(3), f(4) Jawab : f(1) = 2f(0) + 3 = 2 = 9 f(2) = 2f(1) + 3 = 2 = 21 f(3) = 2f(2) + 3 = 2 = 45 f(4) = 2f(3) + 3 = 2 = 93
bilqis26 Recursively Defined Functions How can we recursively define the factorial function f(n) = n! ? f(0) = 1 f(n + 1) = (n + 1)f(n) Hitung f(4) Jawab : f(4) = 4f(3) = 4 6 = 24 f(3) = 3f(2) = 3 2 = 6 f(2) = 2f(1) = 2 1 = 2 f(1) = 1f(0) = 1 1 = 1 f(0) = 1
bilqis27 Recursively Defined Functions A famous example: The Fibonacci numbers f(0) = 0, f(1) = 1 f(n) = f(n – 1) + f(n - 2) Hitung f(6) f(6) = f(5) + f(4) = = 8 f(5) = f(4) + f(3) = = 5 f(4) = f(3) + f(2) = = 3 f(3) = f(2) + f(1) = = 2 f(2) = f(1) + f(0) = = 1 f(1) = 1 f(0) = 0
bilqis28 Fungsi rekursif: Fungsi yang dinyatakan dengan “diri sendiri” dalam ukuran yang lebih kecil (secara rekursif), dan nilai eksplisit untuk nilai(-nilai) basis. Contoh: fungsi Fibonacci Basis: fib(0) = 0; fib(1) = 1 Rekursif:fib(n) = fib(n – 1) + fib(n – 2) Ditulis dengan cara lain: n jika n = 0, 1 fib(n) = fib (n – 1) + fib (n – 2) jika n > 1
bilqis29 PR (lihat buku) 3.2 5, 9, 13, 15, 17, 3, 7