Responsive Navbar with Google Search
Basic Python Programs: Series Expansion

Output 1

Series Expansion: Program 2

Output 2

Series Expansion: Program 3

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: Initialize sum to store the cumulative result and term to 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:
  • \[ \text{Next term} = \frac{x^n}{n!} = \text{Current term} \times \frac{x}{n} \]

  • n += 1: Increments the index for the next term.

Output 3