Lesson 1 of 15
Sequences
Sequences
A sequence is an ordered list of numbers indexed by the natural numbers. In real analysis, we write a sequence as ((a_n)_{n=1}^{\infty}) or simply ((a_n)).
Defining Sequences
A sequence is defined by a rule that assigns a real number to each natural number (n):
def a(n):
return 1 / n # The sequence 1, 1/2, 1/3, 1/4, ...
Common Sequences
| Sequence | Formula | First terms |
|---|---|---|
| Harmonic | (1/n) | 1, 1/2, 1/3, 1/4, ... |
| Geometric | (r^n) | r, r², r³, ... |
| Alternating | ((-1)^n / n) | -1, 1/2, -1/3, ... |
Computing Terms
We can compute and examine any finite number of terms:
terms = [1/n for n in range(1, 11)]
print(terms)
Bounded Sequences
A sequence is bounded above if there exists (M) such that (a_n \le M) for all (n). It is bounded below if there exists (m) such that (a_n \ge m) for all (n).
Your Task
Implement compute_sequence(f, n) that takes a function f defining a sequence and an integer n, and returns a list of the first n terms: [f(1), f(2), ..., f(n)].
Also implement is_bounded(f, n, lower, upper) that checks whether all of the first n terms satisfy lower <= f(k) <= upper.
Pyodide loading...
Loading...
Click "Run" to execute your code.