Arithmetic Sequence
An arithmetic sequence is a sequence of numbers in which the difference between consecutive terms is constant. This difference is called the common difference (d).
Formula: an = a1 + (n−1) * d
where:
- an is the n-th term,
- a1 is the first term,
- d is the common difference,
- n is the term number.
Sum of the first n terms: Sn = (n/2) * (2 * a1 + (n−1) * d)
Python Implementation:
def arithmetic_sequence(a1, d, n):
return [a1 + (i * d) for i in range(n)]
def arithmetic_sum(a1, d, n):
return (n / 2) * (2 * a1 + (n - 1) * d)
# Example usage
a1 = 2
d = 3
n = 10
sequence = arithmetic_sequence(a1, d, n)
sequence_sum = arithmetic_sum(a1, d, n)
print("Arithmetic Sequence:", sequence)
print("Sum of Arithmetic Sequence:", sequence_sum)
Output
Arithmetic Sequence: [2, 5, 8, 11, 14, 17, 20, 23, 26, 29] Sum of Arithmetic Sequence: 155.0
Sequence and Series in Python
Sequences and series are fundamental concepts in mathematics. A Sequence is an ordered list of numbers following a specific pattern, while a series is the sum of the elements of a sequence. This tutorial will cover arithmetic sequences, geometric sequences, and how to work with them in Python.