Series Expansion
Algorithm for Summing Natural Numbers
Input:
Set \( n = 50 \) (the upper limit of the natural numbers to sum).
Initialize Variables:
- Set
total = 0to store the sum of the natural numbers. - Set
series = ""to store the string representation of the series.
Loop from 1 to \( n \):
For each \( i \) from 1 to \( n \) (i.e., \( i = 1, 2, 3, \ldots, n \)):
- Add \( i \) to
total(i.e.,total += i). - Append the string representation of \( i \) followed by " + " to
series(i.e.,series += f"{i} + ").
Output the Series:
Print the string series which contains the natural numbers from 1 to \( n \) concatenated with " + " symbols.
Output the Total Sum:
Print the value of total, which represents the sum of natural numbers from 1 to \( n \).
Series Expansion
Series Expansion
Exponential Function Taylor Series Expansion
The exponential function \( e^x \) can be expressed as a Taylor series expansion around \( x = 0 \):
\[ e^x = \sum_{n=0}^{\infty} \frac{x^n}{n!} = 1 + \frac{x}{1!} + \frac{x^2}{2!} + \frac{x^3}{3!} + \ldots \]
This series converges for all real values of \( x \) and provides a way to approximate \( e^x \) by summing a finite number of terms.
Variable Initialization:
x = 5: Set the value for which \( e^x \) will be computed.tol = 1e-16: Define the tolerance level for convergence, ensuring that the algorithm stops when the terms become sufficiently small.sum, term = 0, 1: Initializesumto store the cumulative result andtermto represent the current term in the series (starting at 1, which corresponds to \( \frac{x^0}{0!} = 1 \)).n = 1: Initialize the term index, which is used to compute factorials.
Loop for Series Calculation:
The loop continues until the absolute value of the current term is less than the tolerance level. This ensures the approximation is accurate.
Inside the loop:
sum += term: Adds the current term to the cumulative sum.term = term * x / n: Calculates the next term in the series using the current term. This formula uses the property of the series:n += 1: Increments the index for the next term.
\[ \text{Next term} = \frac{x^n}{n!} = \text{Current term} \times \frac{x}{n} \]